I was wondering if you can have more than just one base case on a recursive procedure/function in Pascal.
If so, can you please give me a simple example? And please explain why this is possible?
The simple Fibonacci sequence has two base cases:
f(0) = 0 f(1) = 1 f(n) = f(n - 1) + f(n - 2)
And, of course, you can write it in Pascal:
function Fib(n: integer): integer; begin if n = 0 then Fib := 0 else if n = 1 then Fib := 1 else Fib := Fib(n - 1) + Fib(n - 2) end;