ABAP Loops General Commands


Example

To break loops, the command EXIT can be used.

DO.
    READ TABLE itab INDEX sy-index INTO DATA(wa).
    IF sy-subrc <> 0.
        EXIT. "Stop this loop if no element was found
    ENDIF.    
    " some code
ENDDO.

To skip to the next loop step, the command CONTINUE can be used.

DO.
    IF sy-index MOD 1 = 0.
        CONTINUE. " continue to next even index
    ENDIF.
    " some code  
ENDDO.

The CHECK statement is a CONTINUE with condition. If the condition turns out to be false, CONTINUE will be executed. In other words: The loop will only carry on with the step if the condition is true.

This example of CHECK ...

DO.
    " some code
    CHECK sy-index < 10.        
    " some code
ENDDO.

... is equivalent to ...

DO.
    " some code
    IF sy-index >= 10.
        CONTINUE.
    ENDIF.
    " some code
ENDDO.