4 ms·
COBOL programs are divided into paragraphs that start with a paragraph name and have a group of statements within the paragraph. A program starts at the first
by prirun 7y ago
COBOL programs are divided into paragraphs that start with a paragraph name and have a group of statements within the paragraph. A program starts at the first paragraph and continues sequentially through multiple paragraphs until a STOP RUN statement is executed or it executes the last statement in the last paragraph. Easy peasy.
Well, not so fast. If you PERFORM a paragraph, then it's like a BASIC GOSUB statement, or "jump and store" in assembly language. Sort of like a function call, but with no local variables.
Or you can do PERFORM A THRU B to jump to paragraph A, continuing sequentially until the end of paragraph B.
Or you can do PERFORM A THRU B VARYING X FROM 1 BY 1 UNTIL C, which is sort of like a for loop.
The nasty thing about all this is that looking at a paragraph (block of code), you can't tell shit about how it gets executed. Does it fall through to the next paragraph? You can't tell: that's determined dynamically at runtime. Is it a loop? Can't tell. That's one of the things that makes large COBOL programs really hard to understand.
Another fun COBOL statement is ALTER:
https://riptutorial.com/cobol/example/19820/a-contrived-example-using-alter https://riptutorial.com/cobol/example/19820/a-contrived-exam...
If you think GOTO is bad, it's a walk in the park compared to the lethal combination of ALTER + GOTO. Basically, when you say GO TO A, it can go to some other place based on a previous ALTER statement. Now we're having fun!