FOR statement
This adds a FOR statement, following this syntax:
FOR i FROM x TO y STEP z DO
#FOR body
NEXT
where i is a number variable and x, y and z are number variables or literals.
First, it assigns x to i and starts an iteration. At the start of an iteration, the condition i <= y is evaluated if x < y and i >= y otherwise. If the condition passes, the FOR body is executed, if it fails the loop ends. After the body is executed, i is incremented by z and a new iteration is started (checking the condition and so on).
The BREAK and CONTINUE statements can be using inside FOR loops.
I used NEXT to mark the end of a FOR loop, but it could be REPEAT like in the WHILE loop without any trouble, if you prefer it.
Examples:
DATA:
i is number
PROCEDURE:
for i from 0 to 10 step 2 do
if i is greater than 7 then
break
end if
display i " "
next
outputs 0 2 4 6 .
DATA:
i is number
PROCEDURE:
for i from 5 to 0 step -1 do
if i is equal to 3 then
continue
end if
display i " "
next
outputs 5 4 2 1 0 .