Summary -

In this topic, we described about the below sections -

CONTINUE statement skips the current iteration and control passes to the next iteration. CONTINUE statement can be used as conditional or unconditional based on the requirement/usage. Generally CONTINUE statement comes up along with a condition.

If the condition is true and CONTINUE statement executed, the set of statements immediately after the CONTNUE gets bypassed or skipped. If CONTINUE statement coded without condition, then the statements immediately after CONTINUE gets always bypassed.

CONTINUE statement can't able to terminate the loop and only bypasses the set of statements. CONTINUE statement should ends with period (.).

Syntax -

CONTINUE.

Below diagram decribes the flowchart of CONTINUE statement -

Continue Statement Flow Diagram

  • Looping condition - Specifies the condition with loop statement(DO/WHILE).
  • Loop control condition - Specifies the condition with loop control condition.

Execution process -

Step1 - If the looping condition is true, then loop control condition gets validated.

Step2 - If loop control condition is true, CONTINUE statement gets executed. Statements-block1 execution gets bypassed and control transfers to validate looping condition.

Step3 - If loop control condition is false, statements-block1 gets executed and control transfers to validate looping condition.

Step4 - step-1 to step-3 executed repeatedly until the loop condition is false.

Step5 - If loop condition is false, control transfers to statements-block2 or next executable statements if any.


Example -

Below example shows how the CONTINUE coded in the application program.


Code -

*&---------------------------------------------------------------------*
*& Report  Z_CONTINUE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*

REPORT  Z_CONTINUE.

* Declaring Variable
DATA: W_I TYPE I VALUE 0.

* DO loop iterates 10 times
DO 10 TIMES.

* incrementing Iteration number
  W_I = W_I + 1.

* Skips displaying iteration between 5 and 7.
  IF W_I BETWEEN 5 AND 7.
    CONTINUE.
  ENDIF.

* Displays Iteration number
  WRITE : /'Iteration ',W_I.

ENDDO.

Output -

Continue Statement Example Output

Explaining Example -

In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.

DO 10 TIMES, iterates loop 10 times. W_I = W_I + 1, used to display the iteration number for understanding and have no impact on loop iteration.

IF W_I BETWEEN 5 AND 7 condition satisfies, CONTNUE statement gets executed, control transfers to next iteration and skips the statements after CONTINUE statement.