Monday, 28 July 2014

COBOL VARYING phrase PERFORM

The VARYING phrase PERFORM is similar to the UNTIL phrase PERFORM in the sense that the specified range is executed repetitively until the condition becomes true. 

Further, an identifier is set to some initial value and it is incremented or decrement each time the procedure(s) is executed.

Format : PERFORM [procedure-name]
                          [WITH TEST {BEFORE | AFTER}]
                          [VARYING identifier-1\
                 FROM {identifier-2 | integer-1} BY {identifier-3 | integer-2}
                 UNTIL condition
                           [statement-1 ...]
             [END-PERFORM]

The execution of VARYING phrase PERFORM can be easily understood from the following flow chart.


Note: When TEST BEFORE is indicated, all specified conditions are tested before the first execution and the statements to be performed are executed, if at all, only when all specified tests fail. When TEST AFTER is indicated, the statements t o be performed are executed at least once, before any condition is tested. If neither the TEST BEFORE nor the TEST AFTER phrase is specified, the TEST BEFORE phrase is assumed.

Example : 



Created with Artisteer

No comments:

Post a comment