--
-- This is a test of nested recursive parameterless procedure
-- calls with local variables and forward declarations.
--
package test17 is body
    i, answer : integer;
    procedure factorial() is
	j : integer;
	procedure times();
	procedure fact() is begin
	    -- "times" computes "answer := answer * j;"
	    if j <= i then times(); j := j + 1; fact(); end if;
	end;
	procedure times() is
	    i : integer;
	begin
	    i := answer;
            i := i * j;
            answer := i;
	end;
    begin
	answer := 1;
	j := 1;
	fact();
    end;
begin 
    write ("The first 5 factorials are (in ascending order):");
    i := 1;
    loop
	exit when i > 5;
        factorial();
        write("factorial(", i, ") = ", answer);
	i := i + 1;
    end loop;
end.
