Loop – AMT Datasouth PAL User Manual
Page 135
![background image](/manuals/733850/135/background.png)
129
loop
loop
Description
Repetitively executes the specified procedure until the interpreter encounters an exit operator.
Usage
AnyProc
loop
AnyProc
Procedure. The procedure which the interpreter will repetitively execute.
Comments
PAL first removes the supplied procedure from the stack. The interpreter then continuously
executes the procedure until the interpreter encounters an exit operator. The loop operator does
not place any objects on the operand stack. However, the procedure may place objects on the stack
if desired.
Hints
The following three PAL sequences perform entirely different functions.
1:
MyProc loop
2:
/MyProc loop
3:
{MyProc} loop
The first example instructs PAL to execute the procedure MyProc before PAL executes the
operator loop. As a result, the loop operator will generate an error unless MyProc places a pro-
cedure object onto the stack before terminating.
In the second example, when the loop operator executes, it will encounter a literal name
(/MyProc) on the stack. Since loop expects a procedure object, this will produce an error.
The third example shows the proper approach to repetitively execute the procedure MyProc. The
loop operator will repetitively execute the procedure "{MyProc}". The procedure, in turn, executes
the procedure MyProc. Since the "{MyProc}" procedure does not include an exit operator, the
MyProc procedure must contain an exit operator. Otherwise, the loop will continue to execute
forever.
The specified procedure may also do more than just execute a saved procedure. The following ex-
ample sums a series of numbers on the operand stack until it encounters a zero.
dup 0 ne {{exch dup 0 eq {pop exit} if add} loop} if