FOR Command¶
Material prepared from M Programming Book (Page 108) [WALTERS1997] and GT.M Programmer’s Guide
Command¶
F[OR] [variable=start[:increment[:limit]]][,...]
Description¶
FOR will repeat the remaining commands on the line, incrementing
variable by increment until
variablewould be greater thanlimitifincrementis non-negative.variablewould be less thanlimitifincrementis negative.
This means that FOR I=10:-1:1 WRITE I,! will print the numbers from
10 to 1 in descending order as expected. variable will not be beyond limit after the loop exits.
Omitting limit will cause the loop to continue endlessly unless a command
inside the loop causes it to end (e.g. QUIT).
Block Structuring¶
FOR can loop over more than the remainder of the line by using DO or
XECUTE. Additional lines are indented with a period and a space.