while (roll option): Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
 
(8 intermediate revisions by 5 users not shown)
Line 4: Line 4:
'''Introduced''': Version 1.3.b46
'''Introduced''': Version 1.3.b46


Repeatedly executes a statement until a condition becomes false.
Repeatedly executes a statement until a condition becomes false.<br>
The default '''separator''' is {{code|","}}. Some examples of other useful separators: ''nothing'' {{code|""}}, ''space'' {{code|" "}} and ''break'' {{code|"&lt;br>"}}.


====Usage====
====Usage====
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[WHILE(condition): body]
[WHILE(condition): body]
[WHILE(condition, separator): body]
[WHILE(condition, separator): body]
</source>
</syntaxhighlight>


====Example====
====Example====
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h:num = 10]
[h:num = 10]
[WHILE(num >= 0): num = num - 1]
[WHILE(num >= 0): num = num - 1]
</source>
</syntaxhighlight>
Outputs ''9,8,7,6,5,4,3,2,1''
Outputs ''9,8,7,6,5,4,3,2,1''


====Example====
====Example====


This example demonstrates how to put multiple instructions inside a '''while''' loop using the '''CODE''' block extension.
This example demonstrates how to put multiple instructions inside a {{code|while}} loop using the {{roll|code}} block extension.


<source lang="mtmacro" line>
Note the use of the second parameter to {{code|while}} to force a line break in the HTML output.  Also notice that putting text on separate lines does NOT force the output on separate lines; the HTML {{code|&lt;br>}} element is needed for that.
 
<syntaxhighlight lang="mtmacro" line>
[h: End = 5]
[h: End = 5]
[H: Num = 0]
[H: Num = 0]
Line 30: Line 33:
     Next will be [Num+1]
     Next will be [Num+1]
}]
}]
</source>
</syntaxhighlight>
Outputs ''Number is 1, Next will be 2
Outputs:
Number is 2, Next will be 3
 
Number is 3, Next will be 4
{{code|Number is 1, Next will be 2<br>
Number is 4, Next will be 5
Number is 2, Next will be 3<br>
Number is 5, Next will be 6''
Number is 3, Next will be 4<br>
Number is 4, Next will be 5<br>
Number is 5, Next will be 6}}


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

Latest revision as of 23:59, 13 March 2023

 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.
The default separator is ",". Some examples of other useful separators: nothing "", space " " and break "<br>".

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.

Note the use of the second parameter to while to force a line break in the HTML output. Also notice that putting text on separate lines does NOT force the output on separate lines; the HTML <br> element is needed for that.

[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