MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

EXIT. vs CONTINUE.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Mon Jun 18, 2012 1:58 am    Post subject: EXIT. vs CONTINUE. Reply with quote

Just talked to a colleague and we were discussing the above as the ending statement in a section. Where I work, we do not use perform x thru y - only perform on a section. In addition, we allow the use of GO TO as long as it only goes to the end of the section.

Personally, I always use the word exit, since, for me, semantically, CONTINUE could be interpreted as continue on to the next line (I know it doesn't). EXIT, for me, clearly says leave this section. In addition, you have the "ugly" scenario of a possible
Code:

    continue.
d-this-section-ex.
    continue.

as opposed to
Code:

    continue.
d-this-section-ex.
    exit.


NOW TO THE RUB. My colleague said he'd heard an IBM'er say (approx 1998) that you should always use continue rather than loads of exits, since the latter could produce incorrect results.

What do you guys think of continue. vs exit. and has anyone else heard about exits going "wrong" ?
Back to top
View user's profile Send private message Send e-mail
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Jun 18, 2012 9:54 am    Post subject: Reply with quote

misi01,

by definition, an EXIT statement is treated as a CONTINUE - no operational command present.

That said,
EXIT allows one to define a Paragraph - for the end of a PERFORM THRU.

i disagree with the statement
Quote:
you should always use continue rather than loads of exits, since the latter could produce incorrect results


the exits and continues are not causing the problem, incorrect use of PERFORM THRU and GOTO's cause the problem.

I would also, when using SECTIONs:
  • never use PERFORM THRU
  • always use the same name for the exit paragraph (e.g. 9999-EXIT) When you copy a SECTION that has GOTO 9999-EXIT, you don't have to change the name of the exit paragraph, whereas if you attempt to have unique exit paragraph names, you need to insure that you change the name in the new SECTION, otherwise you get an out-of-section transfer of control
  • code as you do. CONTINUE. as last statement in every paragraph and no periods in the paragraph except after the CONTINUE

_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
NorthernDancer
Beginner


Joined: 01 May 2007
Posts: 44
Topics: 22
Location: DOWNTOWN BUFFALO, NY

PostPosted: Wed Jun 20, 2012 8:31 am    Post subject: Reply with quote

I have always used SECTIONs instead of PARAGRAPHS. And only GO TO the xxxxxxxx-SECTION-EXIT. EXIT. to get out. I've always found it makes things easier and clearer to understand. A lot of Programmer I've found don't understand the concept, so don't know how to write using it. At one time years ago, I and another peer found that by using SECTIONs, there cannot be a Fall Through. Don't know if that's still true, but it never happens to me using this method.
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Wed Jun 20, 2012 4:30 pm    Post subject: Reply with quote

Using SECTIONS with any IBM Cobol I know of will not prevent "Fall Through".

Neither the direct "Fall Through" where the main body of code fails to STOP RUN or GOBACK and just "drops" into a SECTION, nor the GO TO to something outside the SECTION currently being performed.

Strange things happen if either of the above are coded in error (or by design, by people who don't know). There is nothing you can do to prevent "Fall Through" except by coding correctly.
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Thu Jun 21, 2012 12:03 am    Post subject: William Reply with quote

if you only use perform on sections and no perform through ....., and assuming all your sections have the word SECTION. included, can you show a scenario where you could fall through ?
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Thu Jun 21, 2012 1:14 am    Post subject: Re: William Reply with quote

misi01 wrote:
if you only use perform on sections and no perform through ....., and assuming all your sections have the word SECTION. included, can you show a scenario where you could fall through ?


Code:
Some stuff which performs everything in the manner described above.

All the SECTIONS described in the manner above.

The GOBACK in the wrong place/missing.


For "Fall Through" it is irrelevant whether SECTION or paragraph are PERFORMed and irrelevant whether TRHU is used or not.

The "classic" "Fall Through" is the above scenario: either like that, or by having a GO TO which manages to avoid the logical ending-point of the program so, "Falls Trhough" into the SECTIONS/paragraphs coded as intended to be PERFORMed.

The ancilliary "Fall Through" is caused through the use of GO TO to a SECTION/paragraph outside the current PERFORM range, or before a PERFORM range is even active.

If you want some fun, try this:

Code:
       ID DIVISION.
       PROGRAM-ID. DEEPDOO.
      *REMARKS. THE PURPOSE OF THIS PROGRAM IS TO SHOW THAT, FAR
      *         FROM "THAT CAN'T BE THE PROBLEM, COBOL DOESN'T DO
      *         THAT", IT IS, AND IT DOES.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  A1-FG PIC X VALUE SPACE.
       01  B1-FG PIC X VALUE SPACE.
       01  C1-FG PIC X VALUE SPACE.
       PROCEDURE DIVISION.
       OBLIGATORY-SECTION SECTION.
           PERFORM A
           IF A1-FG EQUAL TO "Y"
               DISPLAY "DO"
               GO TO G6
           END-IF
           .
       G1.
           PERFORM B
           IF B1-FG EQUAL TO "Y"
               DISPLAY "DOO"
               GO TO G5
           END-IF
           .
       G2.
           PERFORM C
           IF C1-FG EQUAL TO "Y"
               DISPLAY "IN DEEP"
               GO TO G4
           END-IF
           .
       G3.
           GO TO C5
           .
       G4.
           GO TO B5
           .
       G5.
           GO TO A5
           .
       G6.
           MOVE +11 TO RETURN-CODE
           GOBACK
           .
       A SECTION.
           GO TO G1
           .
       A5.
           MOVE "Y" TO A1-FG
           .
       A9.
           EXIT.
       B SECTION.
           GO TO G2
           .
       B5.
           MOVE "Y" TO B1-FG
           .
       B9.
           EXIT.
       C SECTION.
           GO TO G3
           .
       C5.
           MOVE "Y" TO C1-FG
           .
       C9.
           EXIT.
Back to top
View user's profile Send private message
NorthernDancer
Beginner


Joined: 01 May 2007
Posts: 44
Topics: 22
Location: DOWNTOWN BUFFALO, NY

PostPosted: Thu Jun 21, 2012 3:10 pm    Post subject: Reply with quote

I would never use a structure like DEEPDOO in a Production Commercial Application. Has too many GO TOs in it defeating the purpose of part of the original posting. Yikes reminds me of some awful Honeywell GCOS COBOL PGMs from the past G(od's) C(hosen) O(perating) S(ystem) !!
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Fri Jun 22, 2012 2:06 am    Post subject: Reply with quote

I see I didn't make it clear in the "remarks". Definitely, definitely, definitely, not for use in any way, shape or form except to show that leaving PERFORM ranges "active" can give you "interesting" and non-obvious results.

Other than that, the remaining purpose could be deliberate obfuscation, I suppose.

Written after someone came to me with a problem and did not believe my explanation.
Back to top
View user's profile Send private message
delta403
Beginner


Joined: 07 Oct 2010
Posts: 7
Topics: 0
Location: india

PostPosted: Fri Jun 22, 2012 4:13 pm    Post subject: Exit and Continue Reply with quote

First let me describe the difference between EXIT and Continue;
Exit - It will come out the section and control will flow down the section; You can use this, when your program is written in the form of Top to bottom structure.

Continue - will send the control out of the pragraph/section and back to the statment from where the last section was called. Good practice to use this.

Please let me know if you have any question.
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Sat Jun 23, 2012 2:30 am    Post subject: Reply with quote

delta403,

Did you read the post by dbzTHEdinosauer above? "By definition" means "as the manual says".

Your explanation makes no sense, either in itself or when reviewed against the manual.

EXIT "does" nothing. CONTINUE "does" nothing. They are both used at points where the compiler is generating "branches", as in gotos, anyway, so whether present or not the resultant code will be the same.

Try using them interchangeably in a little program you compile, then review the results against your explanation.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group