Page 1 of 1

Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 3:23 pm
by Nischitha Ganesh
Hi,

What is the difference between NEXT Sentence and Continue. My searchs and read about it confuses me more, can someone here please guide.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 4:30 pm
by William Collins
If may be easier if you can let us know what you think the difference is, or what you are unsure about.

My rule is not not use NEXT SENTENCE in any new code, but instead to use CONTINUE and END-IF.

The confusion arises because IBM went against the 1985 ANSI Standard, and allowed NEXT SENTENCE with IF/END-IF and SEARCH/END-SEARCH. For all other COBOLs I know of, NEXT SENTENCE is only allowed within a construct terminated with a full-stop/period.

Code: Select all

IF A EQUAL TO B
    CONTINUE
ELSE
    MOVE B TO C
END-IF
MOVE C TO D

Code: Select all

IF A EQUAL TO B
    NEXT SENTENCE
ELSE
    MOVE B TO C.
MOVE C TO D

Code: Select all

IF A EQUAL TO B
    NEXT SENTENCE
ELSE
    MOVE B TO C
END-IF
MOVE C TO D
The first two examples behave identically.

The third cause some unexpected behaviour, because the NEXT SENTENCE "hunts" for a full-stop/period, and in this case is heading rapidly towards the end of the paragraph/program as the first point where there has to be a full-stop/period.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 4:42 pm
by nicc
And you can avoid CONTINUE and NEXT SENTENCE in the first two examples above by coding:

Code: Select all

IF NOT (A EQUAL TO B)
   MOVE B TO C
END-IF
Some people prefer not to code negative conditions but done like I did it here and to avoid a null THEN it is not so terrible!

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 6:05 pm
by William Collins
Yes, but that's not much use as an illustration of NEXT SENTENCE/CONTINUE :-)

Nice pink, by the way.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 6:31 pm
by nicc
Hi William,
Thanks for the "pinkies"!
It was not, of course, intended to be an illustration of CONTINUE/NEXT SENTENCE but to show that there are alternative, possibly better, ways to code to avoid the situation. You know how it goes: someone sees that code written by an old hand and thinks that that is the way to do it and do so for ever more. I could provide examples in my current place of coding practices that make me cringe - and from guys with decades more COBOL than myself (mainly PL/1 background) - however those are of different constructs so off-topic.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 7:17 pm
by enrico-sorichetti

Code: Select all

IF NOT (A EQUAL TO B)
Ok... I' ll bite ( like a fish )
Just remember I do not speak COBOLESE

wouldn' t it be clearer/simpler to write

Code: Select all

IF A NOT EQUAL TO B 
simple relational expression VS. negation of a simple relational expression

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 7:39 pm
by William Collins
You/re right, Nic. CONTINUE as a replacement for NEXT SENTENCE can be avoided, and I'd code it almost as you have shown (unless site-standards disallow).

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 7:50 pm
by nicc
Hi Enrico

Yes, until you come to more complicated expressions. I like to code as positive and then negate the whole expression. It isn't always that easy - what is? - but a lot of the time it makes it easier to understand. especially when you take into account that someone else may have to read and understand it.

Way off topic!

Re: Difference between NEXT Sentence and Continue.

Posted: Tue May 20, 2014 7:59 pm
by William Collins
Yes, off-topic. I do the same as Nic, with extra brackets. As a means of simplification it works more often than not, in my experience.

The average COBOL coder writes under-average code in general and if it is something important, like a condition, more so. The compiler always understands the way it was coded. The original coder, less often. Those who follow on have to work out whether the code matches the specification before they can do anything.

Re: Difference between NEXT Sentence and Continue.

Posted: Thu Jun 05, 2014 2:36 pm
by Nischitha Ganesh
William Collins wrote:The third cause some unexpected behaviour, because the NEXT SENTENCE "hunts" for a full-stop/period, and in this case is
heading rapidly towards the end of the paragraph/program as the first point where there has to be a full-stop/period.
So in your post all the three posts should work identical right?

Re: Difference between NEXT Sentence and Continue.

Posted: Thu Jun 05, 2014 6:41 pm
by William Collins
No. In the third example, there is no full-stop/period for the END-IF, so NEXT SENTENCE will find the next full-stop/period in the program, and transfer control to that point. At the very least, MOVE C TO D will not be executed when the NEXT SENTENCE leg of the IF is true.

A casual look at the code, and you'd think it works. However, now you know: NEXT SENTENCE + END-IF = Alarm Bell, because mistakes are easy enough to make, without inviting them to set up home in our code.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue Jun 27, 2017 2:21 pm
by Nischitha Ganesh
I found the below code in Prod today and it looks like it's an "alarm bell", right?

Code: Select all

IF (ORH-COMPANY = 'ES') AND                           
   (ORSH-CARRIER-CODE = 'RB')                         
   NEXT SENTENCE                                      
ELSE                                                  
IF (ORH-COMPANY = 'IA' OR 'IN' OR 'LK' OR 'BI') AND   
   (ORSH-BR-NBR-SHIP-FROM NOT = TC-OPER-BR)           
   CONTINUE                                           
ELSE                                                  
IF TC-ORC-CHANGE     AND                              
  ( ORSH-SERIAL-ITEMS AND NOT ORSH-BR-TRANSFER-ORDER )
  AND ORSH-SHIP-VIA NOT = 'BILL ONLY'                 
      PERFORM 930-CHECK-SERIAL-ITEMS                  
      IF WS-ERROR-FOUND                               
         MOVE 'D'     TO  TC-ORC-MODE-SW              
         MOVE 'E'     TO  WS-OUTPUT-SW                
         MOVE SPACE   TO  WS-ERROR-SW                 
      END-IF                                          
END-IF                                                
END-IF                                                
END-IF                                                
END-IF                    
PERFORM 990-TERMINATE-DLI 
PERFORM 980-SCHEDULE-DLI. 

Re: Difference between NEXT Sentence and Continue.

Posted: Tue Jun 27, 2017 4:46 pm
by nicc
What do you mean by "alarm bell"?

Re: Difference between NEXT Sentence and Continue.

Posted: Tue Jun 27, 2017 4:53 pm
by Anuj Dhawan
nicc wrote: What do you mean by "alarm bell"?
I think he is picking it up from here:
William Collins wrote: A casual look at the code, and you'd think it works. However, now you know: NEXT SENTENCE + END-IF = Alarm Bell, because mistakes are easy enough to make, without inviting them to set up home in our code.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue Jun 27, 2017 5:57 pm
by Robert Sample
Since the NEXT SENTENCE bypasses every bit of code you posted and starts with the statement after

Code: Select all

PERFORM 980-SCHEDULE-DLI. 
I would want to review the logic VERY carefully to ensure that this is what is desired, especially since the next IF has a CONTINUE instead of NEXT SENTENCE.

Re: Difference between NEXT Sentence and Continue.

Posted: Tue Jun 27, 2017 8:25 pm
by nicc
Actually, a new topic should have been started as this was tagged onto one 3 years old.

Re: Difference between NEXT Sentence and Continue.

Posted: Wed Jun 28, 2017 9:31 pm
by Nischitha Ganesh
Robert Sample wrote:Since the NEXT SENTENCE bypasses every bit of code you posted and starts with the statement after

Code: Select all

PERFORM 980-SCHEDULE-DLI. 
I would want to review the logic VERY carefully to ensure that this is what is desired, especially since the next IF has a CONTINUE instead of NEXT SENTENCE.
Yes this is confusing and I have asked. I think they should not have used period that ends the confusion.

Re: Difference between NEXT Sentence and Continue.

Posted: Wed Jun 28, 2017 9:41 pm
by Nischitha Ganesh
nicc wrote: Actually, a new topic should have been started as this was tagged onto one 3 years old.
I will take care about this but as this thread was started by me and question was similar I thought to use the same thread. Can we divide it now?

Re: Difference between NEXT Sentence and Continue.

Posted: Wed Jun 28, 2017 10:23 pm
by Robert Sample
Yes this is confusing and I have asked. I think they should not have used period that ends the confusion.
Actually, my thought is that either some more periods are missing, or that the NEXT SENTENCE should not have been used. NEXT SENTENCE goes to the next period and continues with the code after that period -- which for novice COBOL programmers may be quite confusing.

Re: Difference between NEXT Sentence and Continue.

Posted: Thu Jun 29, 2017 10:54 pm
by Nischitha Ganesh
The tester says the results are matching. I am not sure at what condition it will not work.