From STX Wiki
Jump to navigation Jump to search

The FOR loop 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
   // …
The incremental counter variable to initialize with the value init (e.g. #i).
The value with which to initialize the counter variable target (e.g. 0).
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.
The (slightly misleadingly named) step clause is an 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; Variable #i currently is $#i
// an example without initialisation
FOR TO $#x > $#y STEP #i := int $#i + 1
   // do something here …

Neither of target, init, condition and step should ever contain one of the strings "FOR", "TO" or "STEP". If it does, the STx will most likely mistake the line for an ill-formed FOR statement.