while (roll option): Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
Line 20: Line 20:


====Example====
====Example====
This example demonstrates how to put multiple instructions inside a '''while''' loop using the '''CODE''' block extension.
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: End = 10]
[h: End = 5]
[H: Num = 0]
[H: Num = 0]
[WHILE(Num < End), CODE: {[Num = Num + 1]}]
[WHILE(Num < End, "<br>"), CODE: {
    Number is [Num = Num + 1],
    Next will be [Num+1]
}]
</source>
</source>
Outputs ''1, 2, 3, 4, 5, 6, 7, 8, 9, 10''
Outputs ''Number is 1, Next will be 2
Number is 2, Next will be 3
Number is 3, Next will be 4
Number is 4, Next will be 5
Number is 5, Next will be 6''


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

Revision as of 16:31, 15 November 2009

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

WHILE Option

Introduced: Version 1.3.b46

Repeatedly executes a statement until a condition becomes false.

Usage

[WHILE(condition): body]
[WHILE(condition, separator): body]

Example

[h:num = 10]
[WHILE(num >= 0): num = num - 1]

Outputs 9,8,7,6,5,4,3,2,1

Example

This example demonstrates how to put multiple instructions inside a while loop using the CODE block extension.

[h: End = 5]
[H: Num = 0]
[WHILE(Num < End, "<br>"), CODE: {
    Number is [Num = Num + 1],
    Next will be [Num+1]
}]

Outputs Number is 1, Next will be 2 Number is 2, Next will be 3 Number is 3, Next will be 4 Number is 4, Next will be 5 Number is 5, Next will be 6