Ugly Loops
In the context of a loop, there are four kinds of GO TO statements:
- A GO TO which enters the loop.
- A recurrent GO TO -- which returns to the beginning of the loop.
- An exit GO TO -- which leaves the loop.
- An internal GO TO, branching to a paragraph within the loop, but not
to the beginning of the loop.
By definition, a simple loop contains none of the first kind, exactly one
each of the second and third kinds, and none of the last kind. Any
deviation from this pattern makes a loop ugly.
In order to turn an ugly loop into a simple loop, you must eliminate
each of the following ugliness factors, roughly in the order listed:
There may be multiple entry points into
the loop.
The loop may span multiple paragraphs.
There may be multiple recurrent GO TOs.
There may be multiple exit GO TOs.
Control may enter the loop by a GO TO
rather than a PERFORM THRU.
Having done so, you can easily turn the remaining GO TO loop into a
PERFORM UNTIL loop.
COBOL Home
COBOL Style Forum
Spaghetti code