GOTO statement function



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

GOTO statement function

Postby Ajith Kumar » Mon Feb 25, 2008 5:16 pm

Here, i have included coding part. Can anyone give the answer?
will the control back to para-1 if i execute goto statement????

Program:

Perform para-1 thru para-1-exit.
para-1.
Move 1 to ws-count
Display 'aaaa'
Goto para-2
para-1-exit.
Exit.

para-2.
Display 'bbbb'.
Ajith Kumar
 
Posts: 2
Joined: Fri Feb 22, 2008 5:39 pm
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby CICS Guy » Mon Feb 25, 2008 5:54 pm

Ajith Kumar wrote:Here, i have included coding part. Can anyone give the answer?
will the control back to para-1 if i execute goto statement????

Program:
Perform para-1 thru para-1-exit.
para-1.
       Move 1 to ws-count
       Display 'aaaa'
       Goto para-2
para-1-exit.
       Exit.

para-2.
       Display 'bbbb'.
No, whatever is after para-2 will be executed...
If nothing is after para-2, an implicit stop run/goback will take place.
CICS Guy
 
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby Ajith Kumar » Tue Feb 26, 2008 10:51 am

Suppose if there is an 'DISPLAY "cccc"' statement after GOTO statement, will 'cccc' displayed or not?
Ajith Kumar
 
Posts: 2
Joined: Fri Feb 22, 2008 5:39 pm
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby arunprasad.k » Tue Feb 26, 2008 4:33 pm

Ajith Kumar,
Did you tried running your code? You have given the code, then why are you hesitating to run that? Try that and let us know.
Arun.
arunprasad.k
 
Posts: 110
Joined: Thu Dec 27, 2007 5:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby CICS Guy » Tue Feb 26, 2008 7:08 pm

Ajith Kumar wrote:Suppose if there is an 'DISPLAY "cccc"' statement after GOTO statement, will 'cccc' displayed or not?
Of course not, why would you even think it might?
CICS Guy
 
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby pcdoctor » Tue Feb 26, 2008 9:30 pm

Perform cannot contain goto because goto takes the control out of the perform and the control is not returned back.So in your case the control will never come back to para1..To chk ths jus give a display statement in para-1-exit and chk out..Correct me if am wrong pls..

Regards
Nadeem
pcdoctor
 
Posts: 17
Joined: Mon Feb 18, 2008 10:21 pm
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby CICS Guy » Wed Feb 27, 2008 4:10 am

pcdoctor wrote:Perform cannot contain goto because goto takes the control out of the perform and the control is not returned back.
A rather broad statement.....and not entirely correct.....
If the perform was in the paragraph through paragraph form, the 'go to'ed branch could return to a paragraph within the preformed loop....
CICS Guy
 
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: GOTO statement function

Postby dick scherrer » Wed Feb 27, 2008 4:16 am

Hello,

There is also often a big difference between what the compiler will allow and what is good programming practice. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: GOTO statement function

Postby CICS Guy » Wed Feb 27, 2008 4:22 am

pcdoctor wrote:Perform cannot contain goto because goto takes the control out of the perform and the control is not returned back.
FWIW, usually the only 'GO TO's I've seen have been to an abend routine or an EOJ routine.....
CICS Guy
 
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post