D. Pin - 7 months ago 107

Pascal Question

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?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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;
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**