Manual

for
104
for
Description
Performs a procedure for a specified number of iterations.
Usage
StartNum IncNum StopNum AnyProc for
StartNum Integer or fixed-point. Specifies the starting value for a counter maintained by
the interpreter for the loop.
IncNum Integer or fixed-point. Specifies the incrementing value for a counter maintained
by the interpreter for the loop.
StopNum Integer or fixed-point. Specifies the stopping value for a counter maintained by
the interpreter for the loop.
AnyProc Procedure. The procedure executed by the interpreter following every increment
of the counter.
Comments
The interpreter maintains an internal counter associated with each
for
loop encountered. The
for
loop starts by setting this internal counter to the specified StartNum value. Then, if the counter
does not exceed StopNum, the interpreter pushes the counter value onto the stack and executes
AnyProc. Upon completion of AnyProc, the interpreter adds IncNum to the counter. This process
continues until the counter exceeds StopNum.
The interpreter always checks to see if the counter exceeds StopNum before executing the proce-
dure. This means that the interpreter will never execute the procedure if StartNum exceeds
StopNum.
PAL allows both positive and negative values for IncNum. If the programmer specifies a positive
value for IncNum, the loop will terminate when the counter exceeds StopNum in a positive
direction. In other words, when the counter is greater than StopNum.
If the programmer specifies a negative value for IncNum, the loop will terminate when the counter
exceeds StopNum in a negative direction. In other words, when the counter is less than StopNum.
Before every execution of the procedure, PAL pushes the current counter value onto the stack. The
programmer has the responsibility for removing these values from the stack. In many cases, the
procedure will consume the value as part of its normal processing. However, if the procedure does
not require the counter value, the procedure should include a pop operator to remove the value
from the stack.
Hints
The programmer can also use the for operator to accumulate a series of values on the stack for
inserting into an array or other data object. For example, the following PAL code uses an empty
procedure to create an array containing all the even numbers from 14 to 114, inclusive.