Summary: in this tutorial, you will learn how to use the ABAP continue statement to skip the current iteration of a loop.
Introduction to ABAP continue statement
The continue statement skips the current iteration of a loop such as a do loop or a while loop:
continue.Typically, you use the continue statement in conjunction with an if statement.
The following illustrates how to use the continue statement in a do loop:
do n times.
if condition.
continue.
endif.
" other code
enddo.In this syntax, the continue statement will start a new loop iteration immediately. It ignores all the code below the continue between do and enddo.
Similarly, the following shows how to use the continue statement in a while loop:
while condition.
if another_condition.
continue.
endif.
" other code
endwhile.When you use continue statement in a nested loop, it skips the current iteration of the innermost loop.
ABAP continue statement examples
The following example uses the continue statement to skip outputting odd numbers to the screen:
do 10 times.
if sy-index mod 2 = 1.
continue.
endif.
write / sy-index.
enddo.Output:
2
4
6
8
10How it works.
- First, execute the code block 10 times using the
dostatement. - Second, get the remainder of the division of the current loop index (
sy-index) and2. If the remainder is1, skip outputting the current loop index.
Summary
- Use the
continuestatement to skip the current loop iteration and start a new one.