While loop in PL/SQL.
While loop:
That is also iterative type control statement used to repeat a part of program again and again .
It syntax is given as follow:
WHILE condition
LOOP
....BLOCK.....
END LOOP;
Example:
Write a program to read an positive integer from user and display all even n numbers below that integer.
Syntax:
SET SERVEROUTPUT ON
DECLARE
num NUMBER := 16;
BEGIN
WHILE num > 0
LOOP
IF mod(num , 2)=0 THEN
DBMS_OUTPUT.PUT_LINE( 'numbers : ' || num );
END IF;
num := num - 1;
END LOOP;
END;
/
Output:
Comments
Post a Comment