rem ********************************************************* rem * file: loop_ex1.sql rem * desc: This script contains an example of factorial rem * ( Ex: 6! = 1 * 2 * 3 * 4 * 5 * 6 ) rem * calculation using Simple LOOP. rem * Simulation Repeat ... Until LOOP rem * args: none rem * created: by N.Vorobyeva date: Jan 25, 1998 rem * modified: by date: rem ********************************************************* clear screen set ver off set echo off set serveroutput on /* These are SQL*Plus commands for doing I/O They're not part of PL/SQL itself, so you can't, e.g., use them inside a PL/SQL procedure. */ PROMPT Enter NUMBER to calculate a Factorial ACCEPT v_limit DECLARE v_counter INTEGER := 1; v_factorial NUMBER := 1; BEGIN LOOP v_factorial := v_factorial * v_counter; DBMS_OUTPUT.PUT_LINE('Counter = '||v_counter ||', Factorial = '||v_factorial); v_counter := v_counter + 1; EXIT WHEN v_counter > &v_limit; /* v_limit is preceded by an ampersand because it's a SQL*Plus var, read in with above, not an ordinary PL/SQL var. */ END LOOP; DBMS_OUTPUT.PUT_LINE('You''re out when counter = ' || v_counter); -- control transferred here on exit END; /