Product SiteDocumentation Site

2.13. LEAVE


>>-LEAVE--+------+--;------------------------------------------><
          +-name-+

LEAVE causes an immediate exit from one or more repetitive loops or block instruction (simple DO or SELECT).
Processing of the group of instructions is ended, and control is passed to the instruction following the END clause, just as though the END clause had been encountered and the termination condition had been met. However, on exit, the control variable, if any, contains the value it had when the LEAVE instruction was processed.
The name is a symbol, taken as a constant. If name is not specified, LEAVE ends the innermost active repetitive loop. If name is specified, it must be the name of the control variable or LABEL name of a currently active LOOP, DO, or SELECT, which can be the innermost, and that block, and any active block inside it, are then ended. Control then passes to the clause following the END that matches the instruction of the selected block.

Example 2.27. Instructions - LEAVE

max=5
do label myDoBlock /* define a label 'MYDOBLOCK' */
  loop i=1 to max /* label defaults to control variable 'I' */
    if i = 2 then iterate i
    if i = 4 the leave myDoBlock
    say i
  end i
  say 'after looping' max 'times'
end myDoBlock
/* Displays the following
  1
  3
  after looping 4 times
*/

Notes:
  1. If specified, name must match the symbol naming the control variable or LABEL name in the DO, LOOP, or SELECT clause in all respects except the case. No substitution for compound variables is carried out when the comparison is made.
  2. A loop is active if it is currently being processed. If a subroutine is called, or an INTERPRET instruction is processed, during execution of a loop, the loop becomes inactive until the subroutine has returned or the INTERPRET instruction has completed. LEAVE cannot be used to end an inactive block.
  3. If more than one active block uses the same control variable, LEAVE selects the innermost block.