COBOL Perform Until

COBOL Perform Times COBOL Perform Varying

Advertisements


PERFORM UNTIL is mainly used to execute the set/block of statements or paragraph /section until the condition satisfied with UNTIL condition.

PERFORM UNTIL requires to execute repetitively until the specified condition in PERFORM satisfied.

PERFORM TIMES was INLINED and OUTLINED.

PERFORM UNTIL will execute the statements until he specified condition is TRUE.


Syntax:



Inline performOutline perform
UNTIL:

PERFORM UNTIL Condition
       Statements
END-PERFORM.
UNTIL:

PERFORM {Paragraph/Section}      
      [{THROGH/THRU} {Paragraph/Section}      
      UNTIL Condition
WITH TEST BEFORE:

PERFORM WITH TEST BEFORE
       UNTIL Condition
       Statements
END-PERFORM.
WITH TEST BEFORE:

PERFORM {Paragraph/Section}      
      [{THROGH/THRU} {Paragraph/Section}  
      WITH TEST BEFORE    
      UNTIL Condition
WITH TEST AFTER:

PERFORM WITH TEST AFTER
       UNTIL Condition
       Statements
END-PERFORM.
WITH TEST AFTER:

PERFORM {Paragraph/Section}      
      [{THROGH/THRU} {Paragraph/Section}  
      WITH TEST AFTER    
      UNTIL Condition.

Practical Example - Inline PERFORM UNTIL:


Code:



Jcl:



Output:



WITH TEST BEFORE:


WITH TEST BEFORE is used to test the condition before executing the statements block. If the condition is true then simply terminate the loop and control will go to the next statements to be executed.

WITH TEST BEFORE is default with Perform.


Practical Example - Inline PERFROM UNTIL WITH TEST BEFORE:

Code:



Jcl:



Output:



WITH TEST AFTER:


WITH TEST AFTER is used to test the condition after executing the statements block. It will simply execute the statements block without checking the condition, after the iteration completed, it will check for the condition.

i.e. This will execute the statements block once time even though the condition is false for first time too.

WITH TEST AFTER is not default with Perform and used in special cases like the code needs to be executed at least once in any case.


Practical Example - Inline PERFORM UNTIL WITH TEST AFTER:

Code:



Jcl:



Output:



COBOL Perform Times COBOL Perform Varying

Advertisements