PROCEDURE Fibonacci3* (i: SHORTINT): LONGINT;
VAR x: LONGINT; k: SHORTINT; stack: ARRAY 2 OF LONGINT;
BEGIN (* PRE: i >= 0; i <= MaxFibINDEX *)
IF (i = 0) OR (i = 1) THEN RETURN 1
ELSE (* i > 1 *) stack[0] := 1; stack[1] := 1;
k := 2;
REPEAT
x := stack[0] + stack[1]; stack[0] := stack[1];
stack[1] := x;
INC(k);
UNTIL (k > i);
RETURN x
END; (* POST: sBadIndex = FALSE *)
END Fibonacci3;

назад