PERFORM with UNTIL phrase

In the UNTIL phrase format, the procedures referred to are performed until the condition specified by the UNTIL phrase is true Start of changeor for UNTIL EXIT, whenever control is escaped to avoid an infinite loop. For UNTIL with condition-1,End of change control is then passed to the next executable statement following the PERFORM statement.

Format 3: PERFORM statement with UNTIL phrase

Read syntax diagramSkip visual syntax diagramPERFORMprocedure-name-1THROUGHTHRUprocedure-name-2phrase 1phrase 1imperative-statement-1END-PERFORM
phrase 1
Read syntax diagramSkip visual syntax diagramWITHTESTBEFOREAFTERUNTILcondition-1EXIT

If procedure-name-1 is specified, imperative-statement-1 and the END-PERFORM phrase must not be specified.

Can be any condition described under Conditional expressions. If the condition is true at the time the PERFORM statement is initiated, the specified procedures are not executed.

Any subscripting associated with the operands specified in condition-1 is evaluated each time the condition is tested.

Start of change
If the UNTIL phrase with the EXIT reserved word is specified, execution proceeds exactly as if the same PERFORM statement were coded with condition-1 specified, except that condition-1 never evaluates as true.
Note: When UNTIL EXIT is specified, ensure that an escape from the PERFORM loop will be reached. For an inline PERFORM statement, this can be done by an EXIT PERFORM (but not EXIT PERFORM CYCLE) statement. For an out-of-line PERFORM statement, this can be done by a GOBACK or STOP statement. Make sure the escape statement used does escape the PERFORM loop. Several statements might appear to do so, but don't actually escape the loop. For example, an EXIT PARAGRAPH (from a performed paragraph) or an EXIT SECTION (from a performed section) do not escape a PERFORM with the UNTIL EXIT phrase.
End of change

If the TEST BEFORE phrase is specified or assumed, the condition is tested before any statements are executed (corresponds to DO WHILE).

If the TEST AFTER phrase is specified, the statements to be performed are executed at least once before the condition is tested (corresponds to DO UNTIL).

In either case, if the condition is true, control is transferred to the next executable statement following the end of the PERFORM statement. If neither the TEST BEFORE nor the TEST AFTER phrase is specified, the TEST BEFORE phrase is assumed.

Start of changeThe UNTIL EXIT phrase must not be specified with the TEST BEFORE or TEST AFTER phrase nor with the PERFORM with VARYING phrase.End of change