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

 
   
 

The range is repetitively executed for the number of times specified through the identifier or the integer and after that the control goes to the next statement following the PERFORM statement.

Example:


 
 

PERFORM CALCULATE-PARA 5 TIMES.

 
 

In this case the specified CALCULATE-PARA will be repeatedly executed 5 times.

 
  PERFORM BEGIN-PARA THRU END-PARA N TIMES.  
 

In this case the specified range of all paragraphs from BEGIN-PARA to END-PARA will be repeatedly executed n times. Note that the value of n should be available before this statement gets executed.

 
   
   
  PERFORM WITH UNTIL OPTION  
   
 
The format is as follows:

 
   
 

Like the TIMES option, the range is executed repetitively until the specified condition becomes true. It is expected that the condition should be false in the beginning and as a result of the repeated execution of the range, the condition would become true at some stage. However, the PERFORM statement may not be terminated as soon as the condition becomes true. The range must be executed completely before the termination.

Example:


 
  PERFORM READ-PARA UNTIL I > 5.  
 

Here READ-PARA will be executed whenever I <= 5 . When the condition fails it executes READ-PARA and if the condition turns out to be true it skips READ-PARA.

 
  PERFORM BEGIN-PARA THRU END-PARA UNTIL K > N.  
 

It is similar to the previous example. All the paragraphs from BEGIN-PARA to END-PARA will be executed till the specified condition is satisfied.