Chapter 4. Using Flow of Control Statements


In this chapter, you will learn how to

  • Use the compound statement

  • Use labels in both compound statements and loops

  • Work with the two conditional statements (IF and CASE)

  • Implement the four looping statements (FOR, WHILE, REPEAT, and LOOP)

  • Implement the four transfer of control statements (GOTO, LEAVE, ITERATE, and RETURN)

Sequential execution is the most basic path that program execution can take. With this method, the program starts execution at the first line of the code, followed by the next, and continues until the final statement in the code has been executed. This approach works fine for very simple tasks but tends to lack usefulness because it can only handle one situation. Programs often need to be able to decide what to do in response to changing circumstances. By controlling a code's execution path, a specific piece of code can then be used to intelligently handle more than one situation.

Flow of control statements are used to control the sequence of statement execution. Statements such as IF and CASE are used to conditionally execute blocks of SQL PL statements, while other statements, such as WHILE and REPEAT, are typically used to execute a set of statements repetitively until a task is complete.

Although there are many flow of control statements to be discussed in this chapter, there are three main categories: conditional statements, loop statements, and transfer of control statements. Before jumping into a discussion on flow of control statements, it is important to first understand the use of compound statements.



    DB2 SQL PL. Deployment and Advanced Configuration Essential Guide for DB2 UDB on Linux., UNIX, Windows, i5. OS, z. OS
    Intelligent Enterprises of the 21st Century
    ISBN: N/A
    EAN: 2147483647
    Year: 2003
    Pages: 205

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net