EXIT Statement

0

EXIT Statement:

  • “EXIT” Statement is used to terminate a LOOP.
  • Once the loop is terminated, the control passes to the next statement after the “END LOOP”.
  • The “EXIT” statement should always be placed inside the loop only.
  • “EXIT” can be associate with a “WHEN” clause to allow conditional termination of the loop.
  • The “EXIT” condition can be at the top of the loop or at the end of the loop as per logical convenience.
  • Depending upon the circumstances we can make use of this LOOP as Pre-Tested loop or Post-Tested loop construct.
  • The loop terminates its process when the conditional state is “TRUE”.
  • The statement EXIT WHEN condition is equivalent to

IF condition THEN
    EXIT;
END IF;
 

SQL>DECLARE
    v_counter Number:=1;
    BEGIN
        LOOP
    INSERT INTO temp_table
    VALUES(v_Counter,’Loop index’);
    v_Counter:=v_Counter+1;
    EXIT WHEN v_Counter>50;
        END LOOP;
    END;


SQL>DECLARE
    a  NUMBER:=100;
    BEGIN
    LOOP
        IF a=250 THEN
        EXIT;
        END IF;
    a:=a+25;
    display(a);
    END LOOP;
    END;


 Click here to go to Back page

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts