PL/SQL Control Statement Exercises: Using loop with CONTINUE statement
PL/SQL Control Statement: Exercise-21 with Solution
Write a program in PL/SQL using loop with CONTINUE statement.
Sample Solution:
PL/SQL Code:
DECLARE
n NUMBER := 0;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE ('Inside the loop: n = ' || TO_CHAR(n));
n := n + 1;
IF n < 5 THEN
CONTINUE;
END IF;
DBMS_OUTPUT.PUT_LINE
('Inside the loop, after CONTINUE: n = ' || TO_CHAR(n));
EXIT WHEN n = 7;
END LOOP;
DBMS_OUTPUT.PUT_LINE ('When out from the loop: n = ' || TO_CHAR(n));
END;
/
Flowchart:
Sample Output:
SQL> / Inside the loop: n = 0 Inside the loop: n = 1 Inside the loop: n = 2 Inside the loop: n = 3 Inside the loop: n = 4 Inside the loop, after CONTINUE: n = 5 Inside the loop: n = 5 Inside the loop, after CONTINUE: n = 6 Inside the loop: n = 6 Inside the loop, after CONTINUE: n = 7 When out from the loop: n = 7 PL/SQL procedure successfully completed.
Improve this sample solution and post your code through Disqus
Previous: Write a program in PL/SQL using nested loop with EXIT WHEN statement.
Next: Write a program in PL/SQL using loop with CONTINUE WHEN statement.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-21.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics