Difference between revisions of "Command/recurselevel"

From Wiki
Jump to navigation Jump to search
m (Counting up, not down.)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
|attributes=
 
|attributes=
 
}}
 
}}
 +
 +
== [[Help:Reference|Syntax]] (autogenerated) ==
 +
<syntax>recurselevel</syntax>
  
 
== [[Help:Reference|Syntax]] ==
 
== [[Help:Reference|Syntax]] ==
Line 14: Line 17:
 
== Description ==  
 
== Description ==  
  
The iteration count in a {{cmd|dorecurse}} or {{cmd|dostepwiserecurse}}
+
The iteration count in a {{cmd|dorecurse}}, {{cmd|dostepwiserecurse}} or {{cmd|doloop}} block.
loop.
 
  
 
== Example ==
 
== Example ==
Line 27: Line 29:
 
     {\recurselevel...\ }
 
     {\recurselevel...\ }
 
Counting stopped.
 
Counting stopped.
 +
 +
Counting up to 3:
 +
\doloop{
 +
    \ifnum \recurselevel=3
 +
        \exitloop % exit at end of current iteration
 +
    \fi
 +
    \recurselevel!
 +
}
 
</context>
 
</context>
  
Line 40: Line 50:
 
** {{cmd|exitloop}} to exit a loop.
 
** {{cmd|exitloop}} to exit a loop.
 
** {{cmd|exitloopnow}} to immediately exit a loop.
 
** {{cmd|exitloopnow}} to immediately exit a loop.
** {{cmd|looplevel}} to know which iteration the loop is in.
+
** {{cmd|recurselevel}} to know which iteration the loop is in.
** {{cmd|loopdepth}} to know how many nested loops deep we are.
+
** {{cmd|recursedepth}} to know how many nested loops deep we are.
 
* {{cmd|input}} is also often used to produce dummy text.
 
* {{cmd|input}} is also often used to produce dummy text.
 
* [[Programming_in_LuaTeX#Loops_without_worrying_about_expansion|LuaTeX]] for heavier-duty looping and iterating.
 
* [[Programming_in_LuaTeX#Loops_without_worrying_about_expansion|LuaTeX]] for heavier-duty looping and iterating.
Line 50: Line 60:
  
 
[[Category:Command/Internals|recurselevel]]
 
[[Category:Command/Internals|recurselevel]]
 +
table cellspacing="4" cellpadding="2" class="cmd">

Latest revision as of 16:30, 11 November 2019

\recurselevel

Syntax (autogenerated)

\recurselevel


Syntax

\recurselevel

Description

The iteration count in a \dorecurse, \dostepwiserecurse or \doloop block.

Example

Counting up slow:
\dorecurse{10}
    {\recurselevel...\ }

Counting down fast:
\dostepwiserecurse{10}{1}{-2}
    {\recurselevel...\ }
Counting stopped.

Counting up to 3:
\doloop{
    \ifnum \recurselevel=3 
        \exitloop % exit at end of current iteration
    \fi
    \recurselevel!
}

See also

Help from ConTeXt-Mailinglist/Forum

All issues with:

table cellspacing="4" cellpadding="2" class="cmd">