Several of the looping constructs have their own natural terminating conditions. E.g. the "until" loop form stops as soon as its condition evaluates to TRUE.
However, it is sometimes useful to have additional tests for "unusual" exits within the "body" of a loop. The syntax words "quitloop", "quitif", and "quitunless" provide this. They can also be used with an integer specifying which loop to jump out of. The default is 1, meaning jump out of the smallest enclosing loop, whereas quitloop(3) means jump out of the third enclosing loop. These expressions are normally used with conditional tests, e.g.
if list == [] then quitloop(2) endif;Such a test can be abbreviated thus:
quitif(list == [])(2);Similarly there is an analogue of "unless", i.e.
quitunless(x < y);is equivalent to
unless x < y then quitloop() endunless;
Just as it is sometimes useful prematurely to terminate action so is it sometimes useful also to restart a loop prematurely. For example if a loop's body includes a sequence of instructions, then it may be possible to use a time-saving instruction of this form:
if x > y then nextloop(3) endif;This means that if x > y ever evaluates to true, then the third enclosing loop should be re-started. This does not mean that if it is a "for" loop the loop variable should be reset to its initial value. It is equivalent to jumping to just before the end of the loop, e.g. just before "endrepeat", "endwhile", etc., unlike "quitif" and its friends, which jump to just after the end.
In addition to the above commands for quiting or re-starting a loop there are several procedures that can be used to exit from the current procedure, or some other procedure that is `higher up' the control chain. In particular
The following syntax words can be used to deal with more complex cases:
chain, chainto, breakto, catch, jumpout
See HELP CONTROL for more information.
Pop-11 provides a command GO_ON which can be used thus
GO_ON <numerical expression> TO <label1> <label2> <label3> ...<labeln>;The expression must evaluate to a number in the range 1 to N, if N is the number of labels. The labels must be repeated elsewhere in the procedure, followed by colons. For instance, the following will translate numerals:
define trans(num); go_on num to la lb lc ld; la: "one" ; return; lb: "two" ; return; lc: "three" ; return; ld: "toobig"; enddefine; trans(2) => ** twoA GO_ON instruction may end with ELSE <default label>; See HELP GO_ON.