/*-----
    procedure: loopy: void -> void
    purpose: expects nothing, and returns nothing,
       BUT if set serveroutput on 
       and if the dept table from set-up-ex-tbls.sql
       exists,
       it will print
       the results from several example loops to the
       screen

    example: when this is run, IF set serveroutput on,
        and if set-up-ex-tbls.sql has been run,
        you should see:
BURP! 0
BURP! 1
BURP! 2
BURP! 3
BURP! 4
GLIP! 13
GLIP! 14
GLIP! 15
GLIP! 16
Name: Accounting
Name: Research
Name: Sales
Name: Operations
Name: Management

-----*/

create or replace procedure loopy as
    limit integer;
    counter integer;
begin 
    -- demo a PL/SQL while loop

    counter := 0;
    limit := 5;

    while counter < limit
    loop
        dbms_output.put_line('BURP! ' || counter);
        counter := counter + 1;
    end loop;

    -- demo a PL/SQL for loop/count-controlled loop

    for counter in 13 .. 16
    loop
        dbms_output.put_line('GLIP! ' || counter);
    end loop;

    -- demo a simple version of a PL/SQL cursor loop

    for next_row in (select *
                     from   dept)
    loop
        dbms_output.put_line('Name: ' || next_row.dept_name);
    end loop;

end;
/
show errors