Where allowed to run:
|
Parameters Examples Error messages |
The Leave (LEAVE) command ends the processing of commands in the associated DOWHILE, DOUNTIL, or DOFOR loop and passes control to the first command following the associated ENDDO command.
The following command sequence shows this flow.
L1: DOWHILE &LGL1 ... L2: DOWHILE &LGL2 ... IF &LGL3 (LEAVE CMDLBL(L1)) IF &LGL4 LEAVE ... ENDDO /* Here if &LGL4 evaluates to true */ ... ENDDO /* Here if &LGL3 evaluates to true */ ...
Restrictions:
Top |
Keyword | Description | Choices | Notes |
---|---|---|---|
CMDLBL | Command label | Simple name, *CURRENT | Optional, Positional 1 |
Top |
The label must be within the same program as the LEAVE command and be a label on an active DOWHILE, DOUNTIL, or DOFOR group. A CL variable name cannot be used to specify the label name.
Top |
Example 1: Leave Simple DOFOR Loop
DCL VAR(&INT) TYPE(*INT) LEN(2) DCL VAR(&NAME) TYPE(*CHAR) LEN(10) : DOFOR VAR(&INT) FROM(0) TO(10) : (group of CL commands) IF COND(&NAME *EQ *NONE) THEN(LEAVE) : (group of CL commands) ENDDO
The LEAVE command interrupts processing of the active DOFOR group and processing continues with command following the ENDDO.
Example 2: Leave with Nested Loops
DCL VAR(&INT) TYPE(*INT) LEN(2) DCL VAR(&NAME) TYPE(*CHAR) LEN(10) DCL VAR(&LGL) TYPE(*LGL) VALUE('1') /* True */ : LOOP1: DOFOR VAR(&INT) FROM(0) TO(10) : (group of CL commands) LOOP2: DOUNTIL COND(&LGL) : (group of CL commands) IF COND(&NAME *EQ *NONE) THEN(LEAVE CMDLBL(LOOP1)) : (group of CL commands) ENDDO /* DOUNTIL */ : (group of CL commands) ENDDO /* DOFOR */
The LEAVE command interrupts processing of both the active DOUNTIL and DOFOR groups and processing continues with command following the ENDDO matching the DOFOR command.
Top |
None
Top |