| Free-Form Syntax | LEAVE |
| Code | Factor 1 | Factor 2 | Result Field | Indicators | ||
|---|---|---|---|---|---|---|
| LEAVE | ||||||
The LEAVE operation transfers control from within a DO or FOR group to the statement following the ENDDO or ENDFOR operation.
You can use LEAVE within a DO, DOU, DOUxx, DOW, DOWxx, or FOR loop to transfer control immediately from the innermost loop to the statement following the innermost loop's ENDDO or ENDFOR operation. Using LEAVE to leave a DO or FOR group does not increment the index.
In nested loops, LEAVE causes control to transfer “outwards” by one level only. LEAVE is not allowed outside a DO or FOR group.
The ITER (Iterate) operation is similar to the LEAVE operation; however, ITER transfers control to the ENDDO or ENDFOR statement.
For more information, see Branching Operations or Structured Programming Operations.
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+.... CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq.... * * The following example uses an infinite loop. When the user * types 'q', control transfers to the LEAVE operation, which in * turn transfers control out of the loop to the Z-ADD operation. * C 2 DOWNE 1 C : C IF ANSWER = 'q' C LEAVE C ENDIF C : C ENDDO C Z-ADD A B * * The following example uses a DOUxx loop containing a DOWxx. * The IF statement checks indicator 1. If it is ON, indicator * 99 is turned ON, control passes to the LEAVE operation and * out of the inner DOWxx loop. * * A second LEAVE instruction is then executed because indicator 99 * is ON, which in turn transfers control out of the DOUxx loop. * C : C FLDA DOUEQ FLDB C NUM DOWLT 10 C *IN01 IFEQ *ON C SETON 99 C LEAVE C : C ENDIF C ENDDO C 99 LEAVE C : C ENDDO C :