Difference between NEXT Sentence and Continue.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.

Topic author
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm
Has thanked: 1 time

Difference between NEXT Sentence and Continue.

Postby Nischitha Ganesh » Tue May 20, 2014 3:23 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm
Has thanked: 1 time
Been thanked: 25 times

Re: Difference between NEXT Sentence and Continue.

Postby William Collins » Tue May 20, 2014 4:30 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

Re: Difference between NEXT Sentence and Continue.

Postby nicc » Tue May 20, 2014 4:42 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm
Has thanked: 1 time
Been thanked: 25 times

Re: Difference between NEXT Sentence and Continue.

Postby William Collins » Tue May 20, 2014 6:05 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

Re: Difference between NEXT Sentence and Continue.

Postby nicc » Tue May 20, 2014 6:31 pm

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: 822
Joined: Wed Sep 11, 2013 3:57 pm
Been thanked: 69 times

Re: Difference between NEXT Sentence and Continue.

Postby enrico-sorichetti » Tue May 20, 2014 7:17 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm
Has thanked: 1 time
Been thanked: 25 times

Re: Difference between NEXT Sentence and Continue.

Postby William Collins » Tue May 20, 2014 7:39 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

Re: Difference between NEXT Sentence and Continue.

Postby nicc » Tue May 20, 2014 7:50 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm
Has thanked: 1 time
Been thanked: 25 times

Re: Difference between NEXT Sentence and Continue.

Postby William Collins » Tue May 20, 2014 7:59 pm

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.




Topic author
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm
Has thanked: 1 time

Re: Difference between NEXT Sentence and Continue.

Postby Nischitha Ganesh » Thu Jun 05, 2014 2:36 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm
Has thanked: 1 time
Been thanked: 25 times

Re: Difference between NEXT Sentence and Continue.

Postby William Collins » Thu Jun 05, 2014 6:41 pm

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.




Topic author
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm
Has thanked: 1 time

Re: Difference between NEXT Sentence and Continue.

Postby Nischitha Ganesh » Tue Jun 27, 2017 2:21 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

Re: Difference between NEXT Sentence and Continue.

Postby nicc » Tue Jun 27, 2017 4:46 pm

What do you mean by "alarm bell"?


Regards
Nic

User avatar

Anuj Dhawan
Founder
Posts: 2392
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Has thanked: 152 times
Been thanked: 66 times

Re: Difference between NEXT Sentence and Continue.

Postby Anuj Dhawan » Tue Jun 27, 2017 4:53 pm

nicc wrote:Source of the post What do you mean by "alarm bell"?

I think he is picking it up from here:
William Collins wrote:Source of the post 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

Online
User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

Re: Difference between NEXT Sentence and Continue.

Postby Robert Sample » Tue Jun 27, 2017 5:57 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

Re: Difference between NEXT Sentence and Continue.

Postby nicc » Tue Jun 27, 2017 8:25 pm

Actually, a new topic should have been started as this was tagged onto one 3 years old.


Regards
Nic


Topic author
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm
Has thanked: 1 time

Re: Difference between NEXT Sentence and Continue.

Postby Nischitha Ganesh » Wed Jun 28, 2017 9:31 pm

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.




Topic author
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm
Has thanked: 1 time

Re: Difference between NEXT Sentence and Continue.

Postby Nischitha Ganesh » Wed Jun 28, 2017 9:41 pm

nicc wrote:Source of the post 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?



Online
User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

Re: Difference between NEXT Sentence and Continue.

Postby Robert Sample » Wed Jun 28, 2017 10:23 pm

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.




Topic author
Nischitha Ganesh
Registered Member
Posts: 15
Joined: Tue May 20, 2014 2:03 pm
Has thanked: 1 time

Re: Difference between NEXT Sentence and Continue.

Postby Nischitha Ganesh » Thu Jun 29, 2017 10:54 pm

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




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

Who is online

Users browsing this forum: CommonCrawl [Bot] and 2 guests