Programmer Guide/Command Reference/FOR: Difference between revisions
From STX Wiki
Jump to navigationJump to search
(→FOR) |
(→FOR) |
||
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. | |||
FOR [ <var>target</var> := <var>init</var> ] TO <var>cond</var> STEP <var>step</var> | |||
<code>FOR [ <var>target</var> := <var>init</var> ] TO <var>cond</var> STEP <var>step</var> // commands | // commands | ||
// ... | |||
END | |||
;<var>target</var> | ;<var>target</var> | ||
:The incremental counter variable to initialize with the value <var>init</var> (e.g. #i). | :The incremental counter variable to initialize with the value <var>init</var> (e.g. #i). | ||
;<var>init</var> | ;<var>init</var> | ||
: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>cond</var> | ;<var>cond</var> | ||
:The condition which should be tested at the start of each loop (e.g. $#i < 10). See the [[Programmer Guide/Command Reference Intro/condition|condition]] topic for the condition syntax. | :The condition which should be tested at the start of each loop (e.g. $#i < 10). See the [[Programmer Guide/Command Reference Intro/condition|condition]] topic for the condition syntax. | ||
;<var>step</var> | ;<var>step</var> | ||
:The incremental value to add to the counter variable <var>target</var> at the end of each loop. The assignment syntax (e.g. #i := int $#i+1) is allowed. | :The incremental value to add to the counter variable <var>target</var> 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 | |||
// an example without initialisation | |||
FOR TO $#x > $#y STEP #i := int $#i + 1 | |||
END | |||
Revision as of 21:26, 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 cond 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).
- cond
- The condition which should be tested at the start of each loop (e.g. $#i < 10). See the condition topic for the condition syntax.
- 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