The Leave (LEAVE) command can be used to exit an active DOWHILE, DOUNTIL, or DOFOR group.
It provides a structured manner to leave an active group without resorting to the use of the Goto (GOTO) command. LEAVE is not valid with simple Do (DO) command groups.
A Leave (LEAVE) command without a label will leave the innermost active DO group. Specifying a label allows the processing to break out of one or more enclosing groups.
The following illustrates use of the Leave (LEAVE) command:
DO_1: DO_2:DOWHILE &LGL DO_3: DOFOR &INT FROM(0) TO(99) . . . IF (&A *EQ 12) THEN(LEAVE DO_1) . . /* Not processed if &A equals 12 */ . IF (&A *GT 12) LEAVE . . /* Not processed if &A greater than 12 */ . ENDDO . . . IF (&A *LT 0) (LEAVE DO_1) . . /* Not processed if &A less than zero */ . ENDDO
In this example, the labels DO_1 and DO_2 are associated with the DOWHILE group. They can be specified on a LEAVE command appearing in either the DOWHILE or DOFOR group. When &A is equal to 12, the LEAVE DO_1 command is run and processing continues with the CL command following the second ENDDO.
If &A is not equal to 12 but is greater than 12, the DOFOR group is exited and processing continues with next command following the first ENDDO.
When the third If (IF) command is processed and &A is less than zero, processing continues with the next command following the first ENDDO.