Wednesday, December 10, 2008

What is the difference between NEXT SENTENCE and CONTINUE ?

NEXT SENTENCE gives control to the statement following the next period.

CONTINUE gives control to the next (imperative) verb after the explicit scope terminator. (This is not one of COBOL II's finer implementations). It's safest to use CONTINUE rather than NEXT SENTENCE in COBOL II.

Example :
IF A > C
IF A > B
CONTINUE
ELSE
MOVE WS-A TO WS-B
END-IF
MOVE WS-C TO WS-B
END-IF.
MOVE WS-B TO WS-A

In the above example , once the CONTINUE is executed the control will be transfered to next imperative executable statement ( MOVE WS-C TO WS-B).

Whereas, If we use NEXT SENTENCE instead of CONTINUE then control gets transferred to the statement following the next Period (MOVE WS-B TO WS-A).

Hope this helps.
Please do comment if you have any further questions on this.

5 comments:

Maniac said...

IF A > C
IF A > B
CONTINUE
ELSE
MOVE WS-A TO WS-B
END-IF
MOVE WS-C TO WS-B
END-IF.
MOVE WS-B TO WS-A

In the above piece of code, I am still not clear how the "CONTINUE" transfers the control to "MOVE WS-C TO WS-B" verb as A > C is true. If the condition is true why should the ELSE part gets executed? Please clarify.

Maniac said...
This comment has been removed by the author.
Kaps said...

I knew this kind of doubt would be there if I do not use indentation in this example. I tried putting it here, but this site is not allowing me to do it.

Actually there are 2 'IF' statements but the 'ELSE' statement is of 2nd 'IF'.

The statement 'MOVE WS-C TO WS-B', belongs to 'IF" part of first 'IF'.

Let me re write the code, I have put the nos. to distinguish between both 'IF' statements:

_1) IF A > C
_ 2)IF A > B
_ 2) CONTINUE
_ 2)ELSE
_ 2) MOVE WS-A TO WS-B
_ 2)END-IF

_1) MOVE WS-C TO WS-B
_1) END-IF.
MOVE WS-B TO WS-A

I hoe this helps, please let me know if you still face any issue.

Maniac said...

Thanks man! Now the code looks good to me and the difference between NEXT SENTENCE and CONTINUE is clear enough.

Kaps said...

Good , it worked for you.:)