Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, What is "NEXT SENTENCE" suppos 7

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
Hi,
What is "NEXT SENTENCE" supposed to do ?
Thanks
BUILD-RELATIONSHIP-WORK-AREA.
******************************
*
MOVE ALL 'N' TO RELATIONSHIP-SWITCHES.
MOVE LOW-VALUES TO RELATIONSHIP-COUNTERS.
*
IF POLICY-RELATIONSHIPS = SPACE
NEXT SENTENCE
ELSE
PERFORM BUILD-RELATIONSHIP-LOOP
THRU BUILD-RELATIONSHIP-LOOP-X
VARYING REL-SUB FROM 1 BY 1
UNTIL REL-SUB > 10.

BUILD-RELATIONSHIP-WORK-AREA-X.
EXIT.
 
H i Claude,

"Next sent" instructs the pgm to continue execution with the stmt following the next period (.).

The other option is to use "continue" which continues execution after the next "end-if" or the next period (.).

The important thing to remember: Don't use "nxt sent" w/end-if scope delimiters. Execution will continue after the 1st period encountered; not what you intended.

Regards, Jack.
 
Hi,

the program logic is continued after the '.' so starting at label build-relationship-work-area-x. The next sentence does nothing in this case.

The same result you get with:

Code:
      IF POLICY-RELATIONSHIPS NOT = SPACE                       
          PERFORM  BUILD-RELATIONSHIP-LOOP                  
              THRU BUILD-RELATIONSHIP-LOOP-X                
              VARYING REL-SUB FROM 1 BY 1                   
              UNTIL REL-SUB > 10.

In some environments people don't want to use the word NOT.

If you want to use nested coding, so not using a '.', the next sentence can be replaced by a continue.

I hope this is helpful.

Regards,

Crox

 
NEXT SENTENCE is legal only in IF and SEARCH statements -- unless an implementor has extended their use.
DO NOT use NEXT SENTENCE. It will be classified as "archaic" in the next Standard (due next year), which means it will be DROPPED in a future standard.

This is the comment in the Final Committee Draft of the new standard:

NEXT SENTENCE phrase in the IF and SEARCH statements. This phrase can be confusing, especially when
specified in a delimited-scope statement. It is a common belief among users that control is transferred to a
position after the scope delimiter rather than to a separator period that follows it somewhere. In addition, it is
a common source of errors, especially for maintenance programmers who inadvertently insert a period
somewhere before the actual terminating separator period. The CONTINUE statement and scope delimiters
can be used to accomplish the same functionality and such constructs are clearer and less prone to error.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at
 
Stephen, as someone who occasionally uses NEXT SENTENCE, will I still be able to use CONTINUE or something else in order to avoid negative logic?

Also, sometimes NEXT SENTENCE gets me out of a loop, whereas CONTINUE continues inside the loop. Will there be some replacement for NEXT SENTENCE in these instances?

Probably in most cases, there are better ways to exit loops than use NEXT SENTENCE (without having to do negative logic, which I generally cringe at). But aren't there a few cases where NEXT SENTENCE for exiting a loop would be called for?

Nina Too
 
Nina Too
There is a "computer science" tendency to write structured code with no periods except the last one in a paragraph. I'm not sure I like it, but it is there. NEXT SENTENCE will be around for the next 2 standards, at least. (First, it is declared archaic, then obsolete, then eliminated.) It IS not planned that it be replaced. You can use continue, of course, where appropriate, otherwise you will have to get used to negative logic. After all, we ARE professionals.

E-mail me for more info.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
Hi,

The same as people say about next sentence was said about the ALTER statement, say 20 years ago. (I am in business since '79) But if you look up the ALTER in the IBM manual, you will see this:

Code:
0 6.2.3 ALTER Statement
  Ÿ Copyright IBM Corp. 1991, 1998
0
     The ALTER statement changes the transfer point specified in a GO TO
     statement.

     The ALTER statement encourages the use of unstructured programming
     practices; the EVALUATE statement provides the same function as the ALTER
     statement and helps to ensure that your program will be well-structured.

     ³------------------------------------------------------------------------³
     ³                                                                        ³
     ³ >>--ALTER------------------------------------------------------------> ³
     ³                                                                        ³
     ³    <--------------------------------------------------------³          ³
     ³ >----procedure-name-1--TO--³------------³--procedure-name-2-³------->< ³
     ³                            ³-PROCEED TO-³                              ³
     ³                                                                        ³
     ³------------------------------------------------------------------------³
     The ALTER statement modifies the GO TO statement in the paragraph named by
     procedure-name-1.  Subsequent executions of the modified GO TO
     statement(s) transfer control to procedure-name-2.

     procedure-name-1
         Must name a Procedure Division paragraph that contains only one
         sentence:  a GO TO statement without the DEPENDING ON phrase.

     procedure-name-2
         Must name a Procedure Division section or paragraph.


     Before the ALTER statement is executed, when control reaches the paragraph
     specified in procedure-name-1, the GO TO statement transfers control to
     the paragraph specified in the GO TO statement.  After execution of the
     ALTER statement, however, the next time control reaches the paragraph
     specified in procedure-name-1, the GO TO statement transfers control to
     the paragraph specified in procedure-name-2.

     The ALTER statement acts as a program switch, allowing, for example, one
     sequence of execution during initialization and another sequence during
     the bulk of file processing.

     Altered GO TO statements in programs with the INITIAL attribute are
     returned to their initial states each time the program is entered.

   X Do not use the ALTER statement in programs that have the RECURSIVE
   X attribute, in methods, or in AIX, OS/2, or Windows programs compiled with
   X the THREAD option.

So it is still supported.

I think the NEXT SENTENCE clause is not so bad as the ALTER is....

With Friendly Regards,

Crox
 
Hi, StephenJSpiro

Off curse we ARE professionals, thats way we should write code that is easy to understnad and maintain, even for those how isent so experient as WE ARE! Combining NOT, AND and OR can be very confuseing even for the expirient programmer

//Renaldini
 
You can still use CONTINUE, but then you may have to massage the rest of your logic after the scope delimiter. Otherwise, it's &quot;get used to negative logic&quot;, because NEXT SENTENCE _IS_ going away (eventually). Of course, it is always possible that your compiler-maker will continue to support NEXT SENTENCE even after it is dropped from the standard.


Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
Hi,

I think that an experienced programmer, can easily play with AND and OR and NOT, without making mistakes.

I agree that one should avoid not necessary, difficult constructions. But.... Some kinds of problems are not easy and avoid every complexity in the way you make your code can make it also difficult. If you can say things in one expression with some good comments which explain it, you are sometimes better of.

Sometimes you can use brackets to make things easier.

If you can code in a positive way that what you don't want, you can use the brackets and the word NOT.

For example:

IF NOT (IS-RICH AND HAS-A-HIGH-INCOME AND IS-NOT-MARRIED)
WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF

can be better readable than putting the conditions apart without the not or use several IF's or.... Try it!

Regards,

Crox

 
Stephen Spiro wrote:
-----------------
&quot;There is a 'computer science' tendency to write structured code with no periods except the last one in a paragraph. I'm not sure I like it, but it is there.&quot;
-----------------
Yes, alas, I'm aware of that. :-(

I was taught always to end my sentences with periods. :)

And yes, this tendency of writing structured code with no periods except at the end (which COBOL syntax rules allow) can raise all sorts of havoc with NEXT SENTENCE.

Nina Too
 
Crox's sample code:

IF NOT (IS-RICH AND HAS-A-HIGH-INCOME AND IS-NOT-MARRIED)
WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF

Personally, I find it easier to read this as:
IF IS-RICH OR
HAS-A-HIGH-INCOME OR
IS-NOT-MARRIED
CONTINUE [or NEXT SENTENCE]
ELSE
WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF.

But that's just me. Yes, I took Boolean algera and studied De Morgan's theorem. But I still avoid negative logic like the plague. But we will have to see. Perhaps I'll be retired or even dead and gone by the time a COBOL version gets rid of NEXT SENTENCE.

Nina Too
 
Hi Nina,

I am afraid that

IF IS-RICH OR
HAS-A-HIGH-INCOME OR
IS-NOT-MARRIED
CONTINUE [or NEXT SENTENCE]
ELSE
WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF.

is not doing the same as

IF NOT (IS-RICH AND HAS-A-HIGH-INCOME AND IS-NOT-MARRIED)
WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF

If only one of the conditions is NOT true, the refuse-record is written.

I would like to invite anybody to write this in an easier readable way.

Regards,

Crox



 
Hi Nina,

I am afraid that

Code:
IF IS-RICH           OR
   HAS-A-HIGH-INCOME OR 
   IS-NOT-MARRIED
     CONTINUE [or NEXT SENTENCE]
ELSE
   WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF.
[\code]

is not doing the same as

[code]
IF NOT (IS-RICH AND HAS-A-HIGH-INCOME AND IS-NOT-MARRIED)
     WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF
[\code]

If only one of the conditions is NOT true, the refuse-record is written.

I would like to invite anybody to write this in an easier readable way.

Regards,

   Crox
 
Ooops. Let me try again. :)

IF IS-RICH AND
HAS-A-HIGH-INCOME AND
IS-NOT-MARRIED
CONTINUE [or NEXT SENTENCE]
ELSE
WRITE REFUSE-RECORD FROM POSSIBLE-PROSPECT
END-IF.

Hope this works. :-D

Nina Too
 
yes....now i think nina is correct.
It actually depends on situation to go for a negative logic or a positive one.

Regards
Kurup
 
All,

as far as i know a good reason for using NEXT SENTENCE in relation to IF's was the necessity to use both the IF and the ELSE branch. If a dot is your only scope delimiter (COBOL '74), then nesting IF's in the IF branch only will give you a headache fast.

An example:

IF condition-1
IF condition-11
action-11
ELSE
action-2.

Using COBOL '74, this construction probably can't be resolved as desired. Although indentation indicates the ELSE belongs to the first IF, if condition-1 is satisfied and condition-11 isn't, action-2 still will be executed as if the ELSE belonged to the second IF. To resolve this, both IF's should be accompanied with an ELSE:

IF condition-1
IF condition-11
action-11
ELSE
action-12
ELSE
action-2.

If however either action-11 or action-12 isn't needed, replacing it by NEXT SENTENCE will keep the logic as is and eliminates unnecessary actions.
Of course, if you have END-IF's you can use, this argument is mute.

Just my 0.02 euro.

Regards,
Ronald.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top