GO TO
Most authorities urge us to minimize the use of GO TO, if not
completely eliminate it. However, many COBOL programmers still
use GO TO routinely. It is not unusual to find over a hundred GO TOs
in a single program.
Read comp.lang.cobol for a few weeks and you can sample an endless
debate. If your mind is made up and your habits are fixed, then
nothing I can put on these pages is likely to sway you. But if you're
still young and impressionable, or if you're spoiling for a fight,
then consider my summaries of the issues.
In favor of GO TO
Against GO TO
When GO TO might be okay
Conclusions
As you may have guessed, I don't like GO TO. In my entire COBOL career
I have never coded a GO TO. I've never even felt tempted to
code one. That's how unnecessary they are.
(Actually there are two exceptions. I used to code GO TO in old CICS
programs, because the CICS translator forced me to. Also, as a
temporary measure, I sometimes code a GO TO in the course of getting
rid of somebody else's GO TO's.)
If it were up to me to define shop standards, I'm not sure I would
try to impose my tastes on everyone. At a minimum, though, my
standards would say the following:
-
Any program with more than a few GO TOs is a disgrace.
-
Even a single GO TO which could easily be avoided is an embarrassment.
-
While it is possible to imagine cases where a GO TO might be
appropriate, in practice such cases are uncommon.
-
Once you start allowing GO TOs, even where they are appropriate, it
is difficult to keep them from spreading like dandelions. It is better
to ban them outright, with exceptions only in rare and unusual
circumstances.
COBOL Home
COBOL Style Forum