Skip to main content

Fibonacci

func fib(num: Number): Number {    if (num <= 1) return num    return fib(num - 1) + fib(num - 2)}
for (var i = 0; i < 10; i += 1) print(fib(i))

A recursive function that calls itself to calculate the nth number in the fibonacci sequence. This is a simple approach, but not very efficient on high values of n.