{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

section9 - Business Oriented Programming Course 92-252-01...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
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. When we can identify a block of code in the program that performs some specific task (e.g. Prints the report headings) this format allows us to replace the details of how the task is being accomplished with a name that indicates what is being done (e.g.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern