for (roll option): Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 14: Line 14:
</source>
</source>


The ''var'' variable counts from ''start'' to ''end'' during the loop. The optional ''stepsize'' (default +1) is added to var at each iteration.
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''.


====Example====
====Example====
<source lang="mtmacro" line>
[FOR(i,0,10): "i is now " + i]
</source>
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]
Line 23: Line 29:
Counts down even numbers from 10 to 0.
Counts down even numbers from 10 to 0.


|changes=
{{change|1.3b54|Changed the third parameter from the end value to a count value.  In other words, in b53 and earlier, on each iteration it compared if var <= end to determine whether to continue executing the body.  In b54+, it is now comparing if var < end, so the body will never see a value of var equal to end.}}


[[Category:Roll Option]]
[[Category:Roll Option]]
[[Category:Looping Roll Option]]
[[Category:Looping Roll Option]]

Revision as of 00:08, 20 April 2009

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

FOR Option

Introduced: 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]

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.

Example

[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.

|changes=

  • 1.3b54 - {{{2}}}