sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
  PERFORM STATEMENT  
   
  PERFORM WITH THE VARYING - AFTER OPTION  
   
 
The format of PERFORM with VARYING-AFTER option is as follows:

 
   
 

This form is used when a nested repetition of the range is required while varying more than one identifier.

Example:


 
 

PERFORM CALCULATE-PARA
VARYING I FROM 1 BY 1 UNTIL I > 50
AFTER J FROM 1 BY 1 UNTIL J > 10.

 
 

The range CALCULATE-PARA will be perform 500 times - first with I as 1 and J varying from 1 to 10 in step of 1, then I as 2 and again J varying from 1 to 10, and so on. Note that every time I changes value, J must vary from 1 to 10.

Moreover, each time the loop varying J is completed, J is initialized(by 1 in this case) before changing the value of I. Thus after the execution of this PERFORM statement, I will have a value 51 but J will have a value of 1 and not 11.