Skip Headers
Oracle® Database PL/SQL Language Reference
11g Release 2 (11.2)

Part Number E10472-05
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

FOR LOOP Statement

With each iteration of the FOR LOOP statement, its statements run, its index is either incremented or decremented, and control returns to the top of the loop. The FOR LOOP statement ends when its index reaches a specified value, when a statement inside the loop transfers control outside the loop, or when an exception is raised.

Topics:

Syntax

for_loop_statement ::=

for_loop_statement
Description of the illustration for_loop_statement.gif

See statement ::=.

Semantics

index_name

An identifier for the implicitly declared integer variable that is local to the FOR LOOP statement. Statements outside the loop cannot reference index_name. Statements inside the loop can reference index_name, but cannot change its value. After the FOR LOOP statement runs, index_name is undefined.

See Also:

"FOR LOOP Index"

[ REVERSE ] lower_bound .. upper_bound

The lower_bound and upper_bound must evaluate to numbers (see "Lower Bound and Upper Bound"). PL/SQL evaluates lower_bound and upper_bound once, when the FOR LOOP statement is entered, and stores them as temporary PLS_INTEGER values, rounding them to the nearest integer if necessary.

If lower_bound equals upper_bound, the statements run only once.

If lower_bound does not equal upper_bound when the FOR LOOP statement begins to run, then:

label

A label that identifies for_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

Related Topics

In this chapter:

In other chapters: