Nested Loops
0
Nested Loops:
SQL>DECLARE
v_num NUMBER:=1;
BEGIN
LOOP
EXIT WHEN v_num>10;
LOOP
EXIT WHEN v_num>5;
display(‘Inner loop:’||v_num);
v_num:=v_num+1;
END LOOP;
display(‘Outer loop:’||v_num);
v_num:=v_num+1;
END LOOP;
END;
- It is a situation where one loop is embedded into the other.
- The outer loop and the inner loop get associated with one another and execute simultaneously.
- The overall loop terminates is dictated by the outer loop’s “EXIT WHEN” condition or “EXIT” condition.
- In nested loop’s the outer loops condition evaluated as TRUE, always makes the inner loop to resume its process ad the inner loop’s termination actually makes the outer loop to update its process.
SQL>DECLARE
v_num NUMBER:=1;
BEGIN
LOOP
EXIT WHEN v_num>10;
LOOP
EXIT WHEN v_num>5;
display(‘Inner loop:’||v_num);
v_num:=v_num+1;
END LOOP;
display(‘Outer loop:’||v_num);
v_num:=v_num+1;
END LOOP;
END;
0 comments: