This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Business Oriented Programming January 25, 2005 Course 92-252-01 – Spring 2005 SECTION 9 – Iteration In almost every programming job, there is some task that needs to be done over and over – we’ll call this iteration. For example: Processing all records in a file is an iteration of the task – get each record 1 by 1, then process record 1 by 1 until all records have been considered. Other computer languages support a variety of looping constructs, including Repeat, While, and For loops. COBOL has only one iteration verb - PERFORM verb. As we already discussed, a COBOL program processes the statements of the program in sequence, starting at the top of the program and working its way down until the STOP RUN is reached. The PERFORM verb is one way of altering the sequential flow of control in a COBOL program. The PERFORM verb can be used for two major purposes: 1. transfer control to a designated block of code. 2. execute a block of code iteratively. While the other formats of the PERFORM verb implement various types of iteration, the format shown here is used to transfer control to an out-of-line block of code. The block of code may be one or more paragraphs, or one or more sections. The format of the PERFORM verb, transfers control an out-of-line block of code. When the end of the block is reached, control reverts to the statement (not the sentence) immediately following the PERFORM. PERFORM [1 st Proc through EndProc] 1stProc and EndProc are the names of paragraphs or sections. When the PERFORM..THRU is used, the paragraphs or sections from 1stProc to EndProc are treated a single block of code. COBOL programmers typically use this format of the PERFORM to divide a program into open subroutines. PERFORM general notes. PERFORMs may be nested. PERFORMs may execute a paragraph that contains a PERFORM which in turn may execute a paragraph that contains another PERFORM. As control reaches the end of each paragraph it returns to the statement following the perform which cause the paragraph to be executed. Order of execution independent of physical placement The order of execution of the paragraphs is independent of their physical placement. So it doesn't matter where in the Procedure Division we put our paragraphs the PERFORM will find and execute them Recursion not allowed. Although Performs may be nested, neither direct nor indirect recursion is allowed. This means that a paragraph must not contain a PERFORM that invokes itself or any ancestor paragraph (parent, grandparent etc). Unfortunately this restriction is not enforced by the compiler. But, your program will not work correctly if you use recursive Performs This format of the PERFORM verb is used to make programs more readable and maintainable....
View Full Document
This note was uploaded on 11/10/2009 for the course CIS 252 taught by Professor Unknown during the Spring '05 term at Bloomsburg.
- Spring '05