Contoh Looping :
1. Declare
i number(3);
BEGIN
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Ini angka ' || i );
END LOOP;
END;
/
2. Declare
BEGIN
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Ini angka ' || i );
END LOOP;
END;
/
3. Declare
X number(3);
BEGIN
X:=&berapa;
FOR i IN 1..x LOOP
DBMS_OUTPUT.PUT_LINE('Ini angka ' || i );
END LOOP;
END;
/
4. Declare
x number(3);
BEGIN
X:=&berapa;
FOR i IN 1..x LOOP
if mod(i,2) = 1 then
DBMS_OUTPUT.PUT_LINE('Ini angka ' || i );
else
DBMS_OUTPUT.PUT_LINE('Ini angka ' || ‘i’ );
end if;
END LOOP;
END;
/
5. Declare
X number(3);
BEGIN
X:=&berapa;
FOR i IN 1..x LOOP
if mod(x,2) = 1 then
DBMS_OUTPUT.PUT_LINE('proses' );
else
DBMS_OUTPUT.PUT_LINE('lewat' );
end if;
END LOOP;
END;
/
6. Declare
X number(3);
BEGIN
X:=&berapa;
FOR i IN 1..x LOOP
if mod(i,2) = 1 then
for a in 1..i loop
DBMS_OUTPUT.PUT_LINE(a);
end loop;
else
DBMS_OUTPUT.PUT_LINE('lewat');
end if;
END LOOP;
END;
/
7. Declare
X number(3);
BEGIN
X:=&berapa;
FOR i IN 1..x LOOP
for a in 1..i
if mod(i,2) = 1 then
DBMS_OUTPUT.PUT_LINE(a);
else
DBMS_OUTPUT.PUT_LINE('lewat');
end if;
end loop;
END LOOP;
END;
/
8. Declare
X number(3);
BEGIN
X:=&berapa;
FOR i IN 1..x LOOP
if mod(i,2) = 1 then
for a in 1..i loop
DBMS_OUTPUT.PUT_LINE(a);
end loop;
end if;
END LOOP;
END;
/
9. DECLARE
i NUMBER(3);
hasil NUMBER(5);
BEGIN
i:=1;
WHILE i <= 10 LOOP
hasil := i**3;
DBMS_OUTPUT.PUT_LINE(i ||' pangkat 3 = '|| hasil );
i := i + 1;
END LOOP;
END;
/
10. DECLARE
hasil NUMBER(5);
BEGIN
i:=1;
WHILE i <= 10 LOOP
hasil := i**3;
DBMS_OUTPUT.PUT_LINE(i ||' pangkat 3 = '|| hasil );
i := i + 1;
END LOOP;
END;
/
11. DECLARE
i NUMBER(3);
hasil NUMBER(5);
BEGIN
i:=10;
WHILE i <= 10 LOOP
hasil := i**3;
DBMS_OUTPUT.PUT_LINE(i ||' pangkat 3 = '|| hasil );
i := i + 1;
END LOOP;
END;
/
12. DECLARE
i NUMBER(3);
hasil NUMBER(5);
BEGIN
i:=10;
WHILE i <= 10 LOOP
i := i + 1;
hasil := i**3;
DBMS_OUTPUT.PUT_LINE(i ||' pangkat 3 = '|| hasil );
END LOOP;
END;
/
13. DECLARE
i NUMBER(3);
hasil NUMBER(5);
BEGIN
i:=10;
WHILE i <= 10 LOOP
hasil := i**3;
DBMS_OUTPUT.PUT_LINE(i ||' pangkat 3 = '|| hasil );
END LOOP;
END;
/
14. DECLARE
i NUMBER(3);
hasil NUMBER(5);
BEGIN
i:=10;
WHILE i <= 10 LOOP
hasil := i**3;
i := i + 1;
DBMS_OUTPUT.PUT_LINE(i ||' pangkat 3 = '|| hasil );
END LOOP;
END;
/
15. DECLARE
total NUMBER(9);
counter NUMBER(6);
BEGIN
total := 0;
counter := 10;
LOOP
total := total + counter;
EXIT WHEN total > 50;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Counter: ' || counter);
DBMS_OUTPUT.PUT_LINE(' Total: ' || total);
END;
/
16. DECLARE
total NUMBER(9);
counter NUMBER(6);
BEGIN
total := 0;
counter := 10;
LOOP
total := total + counter;
DBMS_OUTPUT.PUT_LINE(' Total: ' || total);
EXIT WHEN total > 50;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Counter: ' || counter);
END;
/
17. DECLARE
total NUMBER(9);
counter NUMBER(6);
BEGIN
total := 0;
counter := 10;
LOOP
total := total + counter;
EXIT WHEN total > 50;
DBMS_OUTPUT.PUT_LINE(' Total: ' || total);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Counter: ' || counter);
END;
/
0 komentar:
Posting Komentar