Oracle® Database PL/SQL Language Reference 11g Release 2 (11.2) Part Number E10472-05 |
|
|
View PDF |
With each iteration of the basic LOOP
statement, its statements run and control returns to the top of the loop. The LOOP
statement ends when a statement inside the loop transfers control outside the loop or when an exception is raised.
Topics:
Syntax
basic_loop_statement ::=
See statement ::=.
Semantics
statement
To prevent an infinite loop, at least one statement must transfer control outside the loop. The statements that can transfer control outside the loop are:
"CONTINUE Statement" (when it transfers control to the next iteration of an enclosing labeled loop)
label
A label that identifies basic_LOOP_statement
(see the syntax diagram statement ::= and the description of label). CONTINUE
, EXIT
, and GOTO
statements can reference this label.
Labels improve readability, especially when LOOP
statements are nested, but only if you ensure that the label at the end of the LOOP
statement matches one of the labels at the beginning of the same statement (the compiler does not check).
Examples
Example 4-10, "Basic LOOP Statement with EXIT WHEN Statement"
Example 4-11, "Nested, Labeled Basic LOOP Statements with EXIT WHEN Statements"
Example 4-13, "CONTINUE WHEN Statement in Basic LOOP Statement"
Related Topics
In this chapter:
In other chapters: