Help with go to statement.

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

Help with go to statement.

Postby Jackfisher » Wed Oct 15, 2014 2:43 am

Hi I am new to cobol. I have a question regarding the use of go to statement. I want to know when how is the control passed when go to is used.
Procedure division
Go to A1000-EXIT.

Perform A2000-Para




my question is once the go to statement is executed control goes to A1000-EXITpara. AAfter that which statement is executed?
A2000-para or A9000 para.
Posts: 1
Joined: Wed Oct 15, 2014 1:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: Help with go to statement.


Re: Help with go to statement.

Postby Robert Sample » Wed Oct 15, 2014 4:20 am

The GO TO -- which is not recommended under most modern programming styles -- acts as an unconditional transfer. In COBOL,
when executed causes the next statement to be executed to be the first statement in A100-EXIT paragraph. When you do a GO TO and it involves a paragraph that is also part of a PERFORM, you can get side effects since the compiler won't know whether the transfer was the result of a PERFORM .. THRU or a GO TO, and hence can attempt to terminate a PERFORM that is not active.

GO TO is no longer needed and hence should NOT be coded in any current programs. The only reason you should know about it is for maintenance of very old programs.
Robert Sample
Global moderator
Posts: 3099
Joined: Sat Dec 19, 2009 8:32 pm
Location: Bellevue, Iowa
Has thanked: 1 time
Been thanked: 176 times

Re: Help with go to statement.

Postby BillyBoyo » Wed Oct 15, 2014 3:01 pm

Hopefully all of any GO TO's that you see will be within a "PERFORM range" and simply going somewhere also within the PERFORM range.

The GO TO A100-EXIT will then reliably "work", but that does not mean it is a good thing to do (although those who use it will think it is good).

Within a PERFORM range, reaching the end of the range, in whatever manner, will transfer control back to the "end" of the PERFORM from whence it came.

If you GO TO within a PERFORM range from outside the range, it is plain asking for trouble.
Global moderator
Posts: 3733
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 254 times

Return to IBM Cobol


  • Related topics
    Last post