The PERFORM verb is how you call
. The basic syntax of a call is simple:
It is also what Cobol uses instead of a while loop
PERFORM MY-ROUTINE UNTIL some-condition.
where the condition
can be algebraic, such as EOF-FLAG = "Y"
or REC-COUNT > 100
; or it can be the peculiar Cobol thing known as an 88 level
, a name for a condition.
It is also what Cobol uses instead of a for loop:
PERFORM MY-ROUTINE VARYING MY-VAR FROM 1 BY 1
UNTIL MY-VAR > 1000.
Ungainly, but not too bad. These for-loops can be nested
within the one command, with up to three variables used:
PERFORM MY-ROUTINE VARYING MY-VAR2 FROM 1 BY 1
UNTIL MY-VAR2 > 1000
AFTER MY-VAR1 FROM 20 BY -2
UNTIL MY-VAR1 = 0.
Routines don't have parameters in Cobol. The variables used in the VARYING clause are ordinary variables defined in the DATA DIVISION; and they can be changed at any time inside the loop being called. This is a good way of screwing up a program, so committed Cobol programmers take advantage of it a lot.
If you're lucky your version of Cobol will support the command EXIT PERFORM, which neatly breaks from the routine or the current iteration. Otherwise, you have to perform a section which is divided up into paragraphs, and GO TO the final, empty paragraph.
You can perform both sections and paragraphs or any simultaneous combination thereof. The best spaghetti comes from mixing levels like this. Each PERFORM keeps track of its own place in the stack and what point should constitute an exit for it, but a well-placed GO TO to outside the currently performed region is always fun and enormously hard to debug, because it doesn't initially occur to you that anyone, not even a Cobol programmer, would be stupid enough to do it.
In COBOL85 apparently they have in-line performs, terminated with END-PERFORM. They probably look like this:
But you're living in some kind of crazed fantasy world
if you think that you as a Cobol programmer are going to see anything as technologically advanced as 1985 Cobol. Even if they can no longer get the licence for COBOL74
and have to upgrade to Cobol85, all the people who wrote the bulk of the system grew up on horn gramophones and those doglegged handles you start the front of a car with, so they won't have used any Cobol85 features. I don't think a serious description of Cobol needs to make reference to anything beyond 1974.