RPG/400 Help

LEAVE (Leave a Do Group)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| LEAVE   |               |                 |                |               |
*---------*---------------*-----------------*----------------*---------------*

The LEAVE operation transfers control from within a do group to the statement following the ENDDO operation.

You can use LEAVE within a DO, DOUxx, or DOWxx loop to transfer control immediately from the innermost loop to the statement following the innermost loop's ENDDO operation. Using LEAVE to leave a do 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 group.

The ITER (Iterate) operation is similar to the LEAVE operation; however, ITER transfers control to the ENDDO statement.

Figure "LEAVE Operation" shows an example of the LEAVE operation.

LEAVE Example

Figure 36. LEAVE Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C* The following example uses an infinite loop.  When the user
C* types 'q', control transfers to the LEAVE operation, which in
C* turn transfers control out of the loop to the Z-ADD operation.
C*
C           2         DOWNE1
C                      :
C           ANSWER    IFEQ 'q'
C                     LEAVE
C                     ENDIF
C                      :
C                     ENDDO
C                     Z-ADDA         B
C*
C*
C* The following example uses a DOUxx loop containing a DOWxx.
C* The IF statement checks indicator 1. If it is ON, indicator
C* 99 is turned ON, control passes to the LEAVE operation and
C* out of the inner DOWxx loop.
C*
C* A second LEAVE instruction is then executed because indicator 99
C* is ON, which in turn transfers control out of the DOUxx loop.
C                      :
C           FLDA      DOUEQFLDB
C           NUM       DOWLT10
C           *IN01     IFEQ *ON
C                     SETON                     99
C                     LEAVE
C                       :
C                     ENDIF
C                     ENDDO
C  99                 LEAVE
C                       :
C                     ENDDO
C                       :


[ Top of Page | Previous Page | Next Page | Table of Contents ]