Difference between NEXT Sentence and Continue.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm

Difference between NEXT Sentence and Continue.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Difference between NEXT Sentence and Continue.

Post 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.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Difference between NEXT Sentence and Continue.

Post 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!
Regards
Nic
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Difference between NEXT Sentence and Continue.

Post by William Collins »

Yes, but that's not much use as an illustration of NEXT SENTENCE/CONTINUE :-)

Nice pink, by the way.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Difference between NEXT Sentence and Continue.

Post 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.
Regards
Nic
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 825
Joined: Wed Sep 11, 2013 3:57 pm

Re: Difference between NEXT Sentence and Continue.

Post 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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Difference between NEXT Sentence and Continue.

Post 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).
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Difference between NEXT Sentence and Continue.

Post 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!
Regards
Nic
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Difference between NEXT Sentence and Continue.

Post 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.
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm

Re: Difference between NEXT Sentence and Continue.

Post 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?
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Difference between NEXT Sentence and Continue.

Post 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.
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm

Re: Difference between NEXT Sentence and Continue.

Post 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. 
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Difference between NEXT Sentence and Continue.

Post by nicc »

What do you mean by "alarm bell"?
Regards
Nic
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Difference between NEXT Sentence and Continue.

Post 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.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1885
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Difference between NEXT Sentence and Continue.

Post 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.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Difference between NEXT Sentence and Continue.

Post by nicc »

Actually, a new topic should have been started as this was tagged onto one 3 years old.
Regards
Nic
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm

Re: Difference between NEXT Sentence and Continue.

Post 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.
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm

Re: Difference between NEXT Sentence and Continue.

Post 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?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1885
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Difference between NEXT Sentence and Continue.

Post 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.
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm

Re: Difference between NEXT Sentence and Continue.

Post by Nischitha Ganesh »

The tester says the results are matching. I am not sure at what condition it will not work.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”