w3resource

PL/SQL Control Statement Exercises: Using loop with CONTINUE WHEN statement

PL/SQL Control Statement: Exercise-22 with Solution

Write a program in PL/SQL using loop with CONTINUE WHEN statement.

Sample Solution:

PL/SQL Code:

DECLARE
  n NUMBER := 0;
BEGIN
  LOOP -- After CONTINUE statement, control resumes here
    DBMS_OUTPUT.PUT_LINE ('The value inside the loop:  n = ' || TO_CHAR(n));
    n := n + 1;
    CONTINUE WHEN n < 4;
    DBMS_OUTPUT.PUT_LINE
      ('The value inside loop, after CONTINUE:  n = ' || TO_CHAR(n));
    EXIT WHEN n = 6;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE ('The value after exit from the loop:  n = ' || TO_CHAR(n));
END;
/

Flowchart:

Flowchart:Using loop with CONTINUE WHEN statement

Sample Output:

The value inside the loop:  n = 0
The value inside the loop:  n = 1
The value inside the loop:  n = 2
The value inside the loop:  n = 3
The value inside loop, after CONTINUE:  n = 4
The value inside the loop:  n = 4
The value inside loop, after CONTINUE:  n = 5
The value inside the loop:  n = 5
The value inside loop, after CONTINUE:  n = 6
The value after exit from the loop:  n = 6

PL/SQL procedure successfully completed.

Improve this sample solution and post your code through Disqus

Previous: Write a program in PL/SQL using loop with CONTINUE statement.
Next: Write a program in PL/SQL to print 1st n numbers.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://www.w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-22.php