Continue and Next Sentence in COBOL

Continue and Next Sentence in COBOL are No Operation statements which does nothing except to pass control to the statement after the scope terminators. But the difference is the place that it passes the control to.

CONTINUE:

Continue gives the control after the next explicit scope terminator. Explicit Scope terminators are END-IF, END-PERFORM, END-EVALUATE, etc.

Example 1:

OPEN INPUT FILE1
IF WW-FILE-STATUS = ‘00’
   CONTINUE
ELSE
    DISPLAY ‘ FILE OPEN FAILED’
END-IF
READ FILE1

In the above code, continue does nothing but it passes control to the statement after end-if.

Example 2:

IF EMP-NUM > ZEROES
   CONTINUE
ELSE
    PERFORM P100-GET-NEXT-EMPL-NUM
END-IF
P200-UPDATE-EMPL-IN-DB

In the above code, the requirement is to update the employee data in a Database for a valid employee number.

NEXT SENTENCE:

It gives control to the next implicit scope terminator which is a period.

Example:

IF WW-VAR1 = WW-VAR2
       NEXT SENTENCE
ELSE
      MOVE WW-VAR-3 TO WW-VAR1
END-IF
IF WW-VAR1 = WW-VAR4
   DISPLAY 'MATCHED'
ELSE
   MOVE WW-VAR4     TO WW-VAR1
END-IF.  -----> Implicit Scope terminator.
PERFORM P100-BUSINESS-LOGIC 

When variable 1 is equal to variable 2 then checking the other IF statements are not required and business logic needs to be performed. So the Next Sentence gives control directly to P100 para which is after the implicit scope terminator(.).

4 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner