Skip Headers

Oracle® OLAP DML Reference
10g Release 1 (10.1)

Part Number B10339-02
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Master Index
Master Index
Go to Feedback page

Go to previous page
Go to next page
View PDF


The WHILE command repeatedly executes a statement while the value of a Boolean expression remains TRUE. You can only use WHILE within a program.


WHILE boolean-expression

    statement block



Serves as the criterion for statement execution. While the expression remains TRUE, statement is repeatedly executed. When the expression becomes FALSE, the execution of statement ceases, and the program continues with the next line. Ensure that something in the statement (or statements) eventually causes the Boolean expression to become FALSE; otherwise, the code becomes an endless loop.

statement block

One or more statements to be executed while the Boolean expression is TRUE. You can execute two or more statements by enclosing them within DO ... DOEND brackets. The DO command should follow immediately after the WHILE command.


WHILE Compared to IF

The WHILE command's main use is as an alternative to the IF...THEN...ELSE command.When you want one or more statements in your program to execute repeatedly for as long as a Boolean expression remains TRUE, you use WHILE. When you want them to execute only once when a Boolean expression is TRUE, you use IF.

Boolean Constant

You can specify a constant for the Boolean expression. When your statement is WHILE TRUE, make sure to include a BREAK, RETURN, or EXIT command between DO ... DOEND so the program can finish the loop.

Branching in a Loop

You can use the BREAK, CONTINUE, and GOTO commands to branch within, or out of, a WHILE loop, thereby altering the sequence of statement execution.

Related Statements

IF...THEN...ELSE, DO ... DOEND, and FOR.


Example 24-42 Using a WHILE Loop in a Program

In the following program lines, the statements following DO are executed as long as the Boolean expression count LT 10 is TRUE. Within the loop, the code searches for an instance of some condition and, when it finds one, it adds 1 to count. When count reaches 10, the loop ends. The code in the loop must ensure that count will, at some time, reach 10. Otherwise, the loop will never end.

WHILE count LT 10
    ..." (statements)
    IF ....
      count = count + 1