PLSQL - While Loop


WHILE
:

We can use While loop to evaluate before each iteration

Statement executed and control resumes at the top of the loop when condition evaluates to TRUE

Loop is bypassed and control passes to next statement when condition evaluates to FALSE

Number of iterations depends on the condition and is unknown until the loop completes


WHILE <condition>

LOOP

statements;

END LOOP;

Example to display 1 to 15 using while loop

declare

x number;

Begin

x := 1;

while x <=15

Loop

dbms_output.put_line(x);

x := x + 1;

End Loop;

end;


Example to Force a loop to complete unconditionally


declare

x number;

/*Use exit after z reaches to 8*/

Begin

x := 1;

while x <=15

Loop

dbms_output.put_line(x);

x := x + 1;

exit when x = 8;

End Loop;

end;

Complete Tutorial

*/

2 comments:


  1. When selecting the right transfer for your project, it's essential to consider the options available. For a variety of sizes, you can explore the DTF Transfers By Size to find the perfect fit. These transfers provide high-quality results and are easy to apply, making them ideal for both beginners and professionals. By choosing the right size, you can ensure your design looks sharp and professional every time.

    ReplyDelete