EXIT
Example
Section titled “Example”DECLARE x NUMBER := 0;BEGIN WHILE x < 10 LOOP x := x + 1; IF x = 5 THEN EXIT; END IF; DBMS_OUTPUT.PUT_LINE('x = ' || x); END LOOP;END;/Output
Section titled “Output”x = 1x = 2x = 3x = 4Explanation
Section titled “Explanation”The EXIT statement terminates the LOOP when x equals 5. So, it prints the values of x from 1 to 4. When x becomes 5, it stops execution and exits the loop. Therefore, the output shows values only from 1 to 4.
Example
Section titled “Example”BEGIN PRINT 'This is before EXIT'; RETURN; -- similar to EXIT PRINT 'This is after EXIT';END;Output
Section titled “Output”This is before EXITExplanation
Section titled “Explanation”In the provided SQL Server script, the RETURN statement (which functions similarly to EXIT in some other programming languages) is used to stop execution of the script. The text ‘This is before EXIT’ is printed to the screen, but ‘This is after EXIT’ is not, because the RETURN statement has halted the script before it can be executed.