for (roll option): Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
m (Applied Template:RollOption; parameters could still using cleaning up.)
Line 1: Line 1:
{{stub}}
{{stub}}
===FOR Option===
{{RollOption
 
|name=for
'''Introduced''': Version 1.3.b46
|version=1.3.b46
 
|description=Executes a statement for a number of iterations based on a start and end value.
Executes a statement for a number of iterations based on a start and end value.
 
====Usage====


|usage=
<source lang="mtmacro" line>
[for(var, start, end): body]
</source>
<source lang="mtmacro" line>
[for(var, start, end, stepsize): body]
</source>
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[FOR(var, start, end): body]
[for(var, start, end, stepsize, separator): body]
[FOR(var, start, end, stepsize): body]
[FOR(var, start, end, stepsize, separator): body]
</source>
</source>
'''Parameters'''<br>
The {{code|var}} variable counts from {{code|start}} towards {{code|end}} during the loop, and the optional {{code|stepsize}} (default {{code|+1}}) is added to {{code|var}} at each iteration.  Note that in the standard incrementing usage with a {{code|stepsize}} of {{code|1}}, the {{code|body}} does not execute when {{code|var}} reaches {{code|end}}.


The ''var'' variable counts from ''start'' towards ''end'' during the loop, and the optional ''stepsize'' (default +1) is added to ''var'' at each iteration.  Note that in the standard incrementing usage with a ''stepsize'' of 1, the ''body'' does not execute when ''var'' reaches ''end''.
|examples=
 
====Example====
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[FOR(i,0,10): "i is now " + i]
[for(i,0,10): "i is now " + i]
</source>
</source>
Counts up from 0 to 9.
Counts up from 0 to 9.


<source lang="mtmacro" line>
<source lang="mtmacro" line>
[FOR(i,10,0,-2): "i is now " + i]
[for(i,10,0,-2): "i is now " + i]
</source>
</source>
Counts down even numbers from 10 to 0.
Counts down even numbers from 10 to 0.


====Version Changes====
|also=
{{change|1.3b54|Changed the comparison operator when comparing the ''var'' to ''end'' when determining whether to continue executing a new iteration.  In b53 and earlier, on each iteration it compared if ''var'' was less than or equal to ''end''.  As of b54, it is now comparing if ''var'' is less than ''end''.}}
{{roll|foreach}}


|changes=
{{change|1.3b54|Changed the comparison operator when comparing the {{code|var}} to {{code|end}} when determining whether to continue executing a new iteration.  In version 1.3b53 and earlier, on each iteration it compared if {{code|var}} was less than or equal to {{code|end}}.  As of version 1.3b54, it is now comparing if {{code|var}} is less than {{code|end}}.}}
}}
[[Category:Roll Option]]
[[Category:Roll Option]]
[[Category:Looping Roll Option]]
[[Category:Looping Roll Option]]

Revision as of 02:30, 20 April 2009

 This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.

[for():] Roll Option

* Introduced in version 1.3.b46

Executes a statement for a number of iterations based on a start and end value.

Usage

[for(var, start, end): body]
[for(var, start, end, stepsize): body]
[for(var, start, end, stepsize, separator): body]

Parameters
The var variable counts from start towards end during the loop, and the optional stepsize (default +1) is added to var at each iteration. Note that in the standard incrementing usage with a stepsize of 1, the body does not execute when var reaches end.

Examples

[for(i,0,10): "i is now " + i]

Counts up from 0 to 9.

[for(i,10,0,-2): "i is now " + i]

Counts down even numbers from 10 to 0.

See Also

[foreach():]

Version Changes

  • 1.3b54 - Changed the comparison operator when comparing the var to end when determining whether to continue executing a new iteration. In version 1.3b53 and earlier, on each iteration it compared if var was less than or equal to end. As of version 1.3b54, it is now comparing if var is less than end.