MODULE 7: COBOL Control statements
PERFORM UNTIL
- This format is used when you want to execute set of instructions multiple times until some condition is met
- Syntax:-
PERFORM [para-1 [{THRU/THROUGH} para-n]] UNTIL condition-1 [statement-block END-PERFORM]Where,
- para-1, para-n are paragraph names which we want to call
- condition-1 is any conditional-expression which can return either true or false
- [statement-block END-PERFORM] is used for Inline PERFORM.
- The data items used in condition(s) must be modified within the paragraph(s) being executed; otherwise the paragraphs will be executed indefinitely
- If the condition coded in UNTIL phrase is met at first time of execution, then specified paragraph(s) will not be executed at all
- Example:-
In PROCUEDURE DIVISION,PARA-0. DISPLAY 'IN PARA-0'. MOVE 1 TO WS-COUNT. PERFORM PARA-1 THRU PARA-1-EXIT UNTIL WS-COUNT < 5. DISPLAY 'IN PARA-0 AGAIN' STOP RUN. PARA-1. DISPLAY 'IN PARA-1 WS-COUNT:' WS-COUNT ADD 1 TO WS-COUNT. PARA-1-EXIT. EXIT.SYSOUT display (output):-IN PARA-0 IN PARA-1 WS-COUNT: 1 IN PARA-1 WS-COUNT: 2 IN PARA-1 WS-COUNT: 3 IN PARA-1 WS-COUNT: 4 IN PARA-0 AGAIN