Programmer Guide/Command Reference/FOR: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 15: Line 15:


;<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 (slightly misleadingly named) <code>step</code> clause is an S_TOOLS-STx statement for incrementing the counter variable <var>target</var> at the end of each loop, e.g. the statement <code>#i := int $#i+1</code>.
  FOR #i := 0 TO $#i < 10 STEP #i := int $#i+1
  FOR #i := 0 TO $#i < 10 STEP #i := int $#i+1
     BUTIL MSGBOX MSG; #i = $#i
     BUTIL MSGBOX MSG; #i = $#i

Revision as of 21:30, 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 (slightly misleadingly named) step clause is an S_TOOLS-STx statement for incrementing the counter variable target at the end of each loop, e.g. the statement #i := int $#i+1.
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

Navigation menu

Personal tools