Loop Control Statements
1. CONTINUE Statement
The CONTINUE statement skips the current iteration and proceed to the next iteration.
DO 10 TIMES.
IF sy-index = 5.
CONTINUE.
ENDIF.
WRITE: / sy-index.
ENDDO.
In this example, if the sy-index is 5, the CONTINUE statement will skip that particular iteration and proceed to the next one.
2. CHECK Statement
The CHECK statement is used to verify a condition within a loop. If the condition evaluates to false, the loop will be exited.
DO 10 TIMES.
indes = index +1.
CHECK index BETWEEN 4 and 8 .
WRITE: / index.
ENDDO.
When the value of index reaches between 4 and 8, the CHECK statement will print the index. the output of the above code will be (4, 5, 6, 7, 8).
3. EXIT Statement
The EXIT statement offers a way to stop and exit from a loop, regardless of the current condition of the loop. This provides control over how the loop is executed.
DO 10 TIMES.
IF sy-index = 5.
EXIT.
ENDIF.
WRITE: / sy-index.
ENDDO.
In this example, the loop is abruptly terminated when sy-index reaches 5, regardless of any ongoing conditions of the loop.