You can leave a loop in pl/sql by specifying a nice litte label to the loop section.
For example: <<firstloop>>
When labeling, you can exit the loop at any time. In following example, lets give the first loop the label <<firstloop>> and so on...
The third loop contains an exit statement when reaching the value of 2. With this exit the control goes back to the end of the first loop!
Usually an exit without labels would only exit the third loop. The first and second loop would run forward.
With this pl/sql label we can skip all of them!
Here's the sample pl/sql code:
dbms_output.put_line('start first loop');
for a in 1..3
for b in 1..3
dbms_output.put_line(' b=' ||b);
for c in 1..3
dbms_output.put_line(' c=' ||c);
exit firstloop when c=2;
end loop thirdloop;
end loop secondloop;
end loop firstloop;
start first loop