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 gives the control after the next explicit scope terminator. Explicit Scope terminators are END-IF, END-PERFORM, END-EVALUATE, etc.
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.
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.
It gives control to the next implicit scope terminator which is a period.
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(.).
What will happen if the continue is used in nested-if?
IF EMP-NUM > ZEROES
IF EMP-AGE > 25
Will the control comes next to nested END-IF or corresponding END-IF?