Difference between NEXT Sentence and Continue.
-
- Registered Member
- Posts: 15
- Joined: Tue May 20, 2014 2:03 pm
Difference between NEXT Sentence and Continue.
Hi,
What is the difference between NEXT Sentence and Continue. My searchs and read about it confuses me more, can someone here please guide.
What is the difference between NEXT Sentence and Continue. My searchs and read about it confuses me more, can someone here please guide.
-
- Global Moderator
- Posts: 490
- Joined: Sun Aug 25, 2013 7:24 pm
Re: Difference between NEXT Sentence and Continue.
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.
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.
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 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.
And you can avoid CONTINUE and NEXT SENTENCE in the first two examples above by coding:
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!
Code: Select all
IF NOT (A EQUAL TO B)
MOVE B TO C
END-IF
Regards
Nic
Nic
-
- Global Moderator
- Posts: 490
- Joined: Sun Aug 25, 2013 7:24 pm
Re: Difference between NEXT Sentence and Continue.
Yes, but that's not much use as an illustration of NEXT SENTENCE/CONTINUE :-)
Nice pink, by the way.
Nice pink, by the way.
Re: Difference between NEXT Sentence and Continue.
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.
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
Nic
-
- Global Moderator
- Posts: 829
- Joined: Wed Sep 11, 2013 3:57 pm
Re: Difference between NEXT Sentence and Continue.
Code: Select all
IF NOT (A EQUAL TO B)
Just remember I do not speak COBOLESE
wouldn' t it be clearer/simpler to write
Code: Select all
IF A NOT EQUAL TO B
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
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
-
- Global Moderator
- Posts: 490
- Joined: Sun Aug 25, 2013 7:24 pm
Re: Difference between NEXT Sentence and Continue.
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.
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!
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
Nic
-
- Global Moderator
- Posts: 490
- Joined: Sun Aug 25, 2013 7:24 pm
Re: Difference between NEXT Sentence and Continue.
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.
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.
-
- Registered Member
- Posts: 15
- Joined: Tue May 20, 2014 2:03 pm
Re: Difference between NEXT Sentence and Continue.
So in your post all the three posts should work identical right?William Collins wrote:The third cause some unexpected behaviour, because the NEXT SENTENCE "hunts" for a full-stop/period, and in this case isheading rapidly towards the end of the paragraph/program as the first point where there has to be a full-stop/period.
-
- Global Moderator
- Posts: 490
- Joined: Sun Aug 25, 2013 7:24 pm
Re: Difference between NEXT Sentence and Continue.
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.
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.
-
- Registered Member
- Posts: 15
- Joined: Tue May 20, 2014 2:03 pm
Re: Difference between NEXT Sentence and Continue.
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.
- Anuj Dhawan
- Founder
- Posts: 2806
- Joined: Sun Apr 21, 2013 7:40 pm
- Location: Mumbai, India
- Contact:
Re: Difference between NEXT Sentence and Continue.
I think he is picking it up from here:
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.
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.
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Difference between NEXT Sentence and Continue.
Since the NEXT SENTENCE bypasses every bit of code you posted and starts with the statement after 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.
Code: Select all
PERFORM 980-SCHEDULE-DLI.
Re: Difference between NEXT Sentence and Continue.
Actually, a new topic should have been started as this was tagged onto one 3 years old.
Regards
Nic
Nic
-
- Registered Member
- Posts: 15
- Joined: Tue May 20, 2014 2:03 pm
Re: Difference between NEXT Sentence and Continue.
Yes this is confusing and I have asked. I think they should not have used period that ends the confusion.Robert Sample wrote:Since the NEXT SENTENCE bypasses every bit of code you posted and starts with the statement afterI 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.Code: Select all
PERFORM 980-SCHEDULE-DLI.
-
- Registered Member
- Posts: 15
- Joined: Tue May 20, 2014 2:03 pm
Re: Difference between NEXT Sentence and Continue.
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?
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Difference between NEXT Sentence and Continue.
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.Yes this is confusing and I have asked. I think they should not have used period that ends the confusion.
-
- Registered Member
- Posts: 15
- Joined: Tue May 20, 2014 2:03 pm
Re: Difference between NEXT Sentence and Continue.
The tester says the results are matching. I am not sure at what condition it will not work.
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