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

 
   
 

This option is similar to the UNTIL option in the sense that the specified range is executed repetitively until the condition becomes true. In addition to this, identifier-1 is set to some initial value and it is incremented each time the range is executed. Identifier-1 must be a numeric data item and an index name can also be used instead of identifier-1. The initial value to which identitfier-1 is set at the beginning is specified through identifier-2 or index-name-2 or Literal-1. The increment by which the value of identifier-1 is increased is specified through identifier-3 or Literal-2 which appears after the phrase BY. The identifiers and literals in the FROM and BY phrases must be numeric and their values can be either positive or negative with or without fractional parts.

Example:


 
 

PERFORM CALCULATE-PARA VARYING K FROM 1 BY 1 UNTIL K > 10.

 
 

Here, CALCULATE-PARA will be repeatedly executed 10 times (For K=1,2,3, …..10).

 
  PERFORM BEGIN-PARA THRU END-PARA VARYING J FROM 1 BY 2 UNTIL J > 100.  
 

Here, paragraphs from BEGIN-PARA through END-PARA will be repeatedly executed for J = 1, 3, 5 …, 99.