Page 1 of 1

Help with go to statement.

PostPosted: Wed Oct 15, 2014 2:43 am
by Jackfisher
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
................................
IF A<B
Go to A1000-EXIT.

Perform A2000-Para
----
-----

A9000-GOBACK
GOBACK.

A1000-EXIT.
EXIT.

A2000-PARA
---
---
A3000-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.

Re: Help with go to statement.

PostPosted: Wed Oct 15, 2014 4:20 am
by Robert Sample
The GO TO -- which is not recommended under most modern programming styles -- acts as an unconditional transfer. In COBOL,
GO TO A100-EXIT
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.

Re: Help with go to statement.

PostPosted: Wed Oct 15, 2014 3:01 pm
by BillyBoyo
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.