Manual

repeat
156
repeat
Description
Executes the specified procedure for the specified number of iterations.
Usage
CountInt AnyProc repeat
CountInt Integer. Specifies the number of times the interpreter should execute AnyProc.
AnyProc Procedure. The procedure which the interpreter will repetitively execute.
Comments
PAL first removes the supplied iteration count and procedure from the stack. The interpreter then
executes the procedure for the specified number of iterations. The repeat operator does not place
any objects on the operand stack. However, the procedure may place objects on the stack if
desired.
The programmer can use the exit operator to prematurely terminate a repeat loop.
Hints
The following three PAL sequences perform entirely different functions.
1: 5 MyProc repeat
2: 5 /MyProc repeat
3: 5 {MyProc} repeat
The first example instructs PAL to execute the procedure
MyProc
before PAL executes the
operator
repeat
. As a result, the
repeat
operator will generate an error unless
MyProc
places a
procedure object onto the stack before terminating.
In the second example, when the
repeat
operator executes, it will encounter a literal name
(/MyProc) on the stack. Since repeat expects a procedure object, this will produce an error.
The third example shows the proper approach to repetitively execute the procedure MyProc. The
repeat
operator will execute the procedure "
{MyProc}
" five times. The procedure, in turn, exe-
cutes the procedure
MyProc
during each iteration.
The specified procedure may also do more than just execute a saved procedure. The following ex-
ample sums ten numbers on the operand stack without removing the values from the stack.
10 {9 index} repeat 9 {add} repeat