Quick Search:
 
 The Oracle WHILE Keyword      [Return To Index] Jump to:  

Term: WHILE

Definition:
A WHILE Loop is used when you want to repeatedly execute statements in a loop body until the specified condition occurs. The condition may be a set value (3, 50, 22,000, etc) or the result of an evaluated expression (temperature < 50).

Example Syntax:
The syntax for the WHILE Loop is:

WHILE (<condition>)
LOOP
{statements to execute}
END LOOP;


An important thing to note is that the WHILE condition is evaluated before entering the loop. Because of this it is possible that the loop body may never get to execute even once if the condition evaluates to false. For example, because '1' will never equal '2', this loop will never execute:

WHILE 1 = 2
LOOP
DBMS_OUTPUT.PUT_LINE('1 equals 2');
END LOOP;


In this example, the WHILE Loop would terminate once the daily_sales exceeded 1000:

WHILE daily_sales <= 1001
LOOP
DBMS_OUTPUT.PUT_LINE('Sales are less than 1000');
END LOOP;


Want to expand, correct, or add to this information? Please contact us!

Related Code Snippets:
 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org