Programmer Guide/Command Reference/FOR: Difference between revisions
From STX Wiki
Jump to navigationJump to search
(→FOR) |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
The <code>FOR</code> executes the commands in the block enclosed by the <code>FOR</code> statement and the corresponding <code>END</code> as long as the (slightly misleadingly named) <code>TO</code> condition holds true. | The <code>FOR</code> executes the commands in the block enclosed by the <code>FOR</code> statement and the corresponding <code>END</code> as long as the (slightly misleadingly named) <code>TO</code> condition holds true. | ||
FOR [ <var>target</var> := <var>init</var> ] TO <var> | FOR [ <var>target</var> := <var>init</var> ] TO [[Programmer_Guide/Command_Reference_Intro/Conditional_Expressions|<var>condition</var>]] STEP <var>step</var> | ||
// commands | // commands | ||
// ... | // ... | ||
Line 11: | Line 11: | ||
:The value with which to initialize the counter variable <var>target</var> (e.g. 0). | :The value with which to initialize the counter variable <var>target</var> (e.g. 0). | ||
;<var> | ;<var>condition</var> | ||
:The condition which should be tested at the start of each loop (e.g. $#i < 10). See | :The condition which should be tested at the start of each loop (e.g. <code>$#i < 10</code>). See [[Programmer_Guide/Command_Reference_Intro/Conditional_Expressions|Conditional Expressions]] for further information on conditional expressions. | ||
;<var>step</var> | ;<var>step</var> |
Revision as of 21:28, 22 March 2011
The FOR
executes the commands in the block enclosed by the FOR
statement and the corresponding END
as long as the (slightly misleadingly named) TO
condition holds true.
FOR [ target := init ] TO condition STEP step // commands // ... END
- target
- The incremental counter variable to initialize with the value init (e.g. #i).
- init
- The value with which to initialize the counter variable target (e.g. 0).
- condition
- The condition which should be tested at the start of each loop (e.g.
$#i < 10
). See Conditional Expressions for further information on conditional expressions.
- step
- The incremental value to add to the counter variable target at the end of each loop. The assignment syntax (e.g. #i := int $#i+1) is allowed.
FOR #i := 0 TO $#i < 10 STEP #i := int $#i+1 BUTIL MSGBOX MSG; #i = $#i END
// an example without initialisation FOR TO $#x > $#y STEP #i := int $#i + 1 // do something here ... END