WHILE Loops

0
WHILE Loops:
  • The WHILE LOOP statement includes a condition associates with a sequence of statement.
  • If the condition evaluates to true, then the sequence of statements will be executed, and again control resumes at the beginning of the loop.
  • IF the condition evaluates to false or NULL, then the loop is bypassed and the control passes to the next statement.

Syntax:
    WHILE condition LOOP
    Statement1;            condition is
    Statement2;            evaluated at the beginning of
    …                each iteration.
    END LOOP;

SQL>DECLARE
    n NUMBER(3):=1;
    v VARCHAR2(100);
    BEGIN
        WHILE n<=10
        LOOP
            v:=v||’ ‘||N;
            n:=n+1;
        END LOOP;
    display(v);
    END;

SQL>DECLARE
    n NUMBER(5):=&N;
    s NUBMER(5):=0;
    r NUMBER(2):=0;
    BEGIN
    WHILE n!=0
    LOOP
    r:=mod(n,10);
    s:=s+r;
    n:=trunc(n/10);
    END LOOP;
    display(‘ The sum of digit of given number is’||s);
    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