DOLOOP <loop count> FROM <initial loop value> TO <final loop value> STEP <loop step size> {
<commands>
}
The DOLOOP command allows <statements> to be executed a defined number of times with an incrementing variable. The loop will always be executed at least once since the loop count variable will be incremented at the end of each loop. This variable, if omitted, is an automatically created word named LOOP. The variable may be used freely within the loop, eg.
DOLOOP LOOP1 FROM 1 TO 8 STEP 2 { ... NEWWORD = POSITION * LOOP1 INC NEWWORD POSSPEC ... }
will execute the commands within curly braces for values of the word LOOP1 1,3,5 and 7.
The loop values may be negative, eg.
will execute the contained commands for values of the variable INDEX of 7,4,1 and -2.DOLOOP INDEX FROM 7 TO -2 STEP -3
To exit from a loop before the loop variable has reached the final loop value the IF... GOTO command should be used.
eg.
DOLOOP FROM X1 TO X2 STEP I { ... IF $...$ GOTO ABCD ... } LABEL ABCD: ...