COBOLbeginner

PERFORM Varieties: THRU, VARYING, UNTIL, and Inline

Master the different forms of PERFORM, COBOL's core control-flow verb for looping and paragraph invocation.

PERFORM is COBOL's Swiss army knife for control flow — it replaces both the function-call and the loop constructs found in modern languages, and interviewers lean on it heavily because there's no single obvious modern analog, so your answer reveals real COBOL experience versus surface familiarity.

PERFORM THRU is like telling someone to read pages 10 through 15 of a binder — it works fine until someone inserts a new page 12 and quietly changes what 'THRU 15' actually covers.

Key Concepts

1
The basic PERFORM paragraph-name executes that paragraph once and returns control to the next statement — effectively a subroutine call within the same program. PERFORM para-1 THRU para-3 executes a contiguous range of paragraphs, which is powerful but dangerous, because it depends on paragraph ordering in the source and is a common source of maintenance bugs when someone inserts a new paragraph in the middle of the range.
PERFORM paragraph-namePERFORM para-1 THRU para-3
2
PERFORM ... UNTIL condition is the pretest loop — condition is checked before each iteration, so a false condition on entry means zero executions unless you add WITH TEST AFTER for a post-test loop. PERFORM ... VARYING is COBOL's counted-loop construct, incrementing an index or counter each pass, and can nest with AFTER clauses to drive multi-dimensional table processing.
PERFORM ... UNTIL conditionPERFORM ... VARYING
3
Modern COBOL also supports in-line PERFORM, where the loop body sits directly between PERFORM and END-PERFORM rather than referencing a separate paragraph — this is closer to how loops read in Java or C#, and increasingly preferred in new code because it avoids the THRU pitfall entirely and keeps logic visually co-located.