Retro school children University of Washington Computer Science & Engineering
 CSE 401: PL/0 - Sample Code
  CSE Home  About Us    Search    Contact Info 

The following PL/0 program is fib.0. What does it do?
module main;
    var result:int;

    procedure fib(arg:int);
	var temp:int;
    begin
	if arg <= 0 then result := 0; end;
	if arg  = 1 then result := 1; end;
	if arg  > 1 then
		fib(arg - 1);
		temp := result;
		fib(arg - 2);
		result := result + temp;
	end;
    end fib;

    var n:int;

begin

    n := input;
    while n <> 0 do
        fib(n);
        output := result;
        n := input;
    end;

end main.