Determine how to begin and end a simple loop within a PL/SQL block.
Programming PL/SQL Loops
A loop is a powerful way of building iterative logic. This lesson introduces you to loops.
The LOOP statement allows you to build iterative controls within your PL/SQL block. LOOP allows you to repeat a sequence of
statements. The statements to be repeated are placed between the keywords LOOP and END-LOOP. The sequence of statements is executed, and then the control resumes at the top of the loop.
If further processing is undesirable or impossible, you can use the EXIT statement to exit the loop.
There are two forms of EXIT statements: EXIT and EXIT-WHEN.
The EXIT statement forces a loop to complete unconditionally.
When an EXIT statement is encountered, the loop completes immediately and control passes to the next statement.
The EXIT statement must always be placed within a loop. You cannot use this statement to complete a PL/SQL block.
The EXIT-WHEN statement allows a loop to complete conditionally. When the EXIT statement is encountered, the condition in the WHEN clause is evaluated.
If the condition evaluates to TRUE, the loop completes and control passes to the next statement after the loop.
The EXIT-WHEN statement replaces a simple IF statement.
Identifying Control Structures
Click the link below to learn about PL/SQL control structures. Identifying Control Structures
In the next lesson, you will observe the structure of FOR and WHILE loops.