Loops
for loop-variable := start to end do
looping-statement
for loop-variable := start to end by index do
looping-statement
for
loop initializes the loop variable to start
. Each time through the loop, the loop variable is compared to end
. If the loop variable is greater than end
, the loop terminates. (If index
is negative, it terminates when less than end
.) Otherwise, the looping statement is executed and the loop variable is incremented by 1 (if index
exists, the variable hops by index
). Then, execution jumps back to the top, with a comparison to end
.
The start
and end
expressions are evaluated exactly once. The looping statement is executed zero or more times. The loop variable is automatically created as a local variable (unless it is already local).
After the loop, the loop variable's value is undefined--don't rely on it.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996