Skip to content
← Index | Lesson 5 of 5

Recursion (Fibonacci)

Recursion

Functions can call themselves:

fn factorial(n: int) -> int {
    if n <= 1 { return 1 }
    return n * factorial(n - 1)
}

print(factorial(5)) // 120

Goal: Implement fibonacci(n) recursively. fibonacci(10) should return 55.

lesson-2-5.zolo
Program output

Run the code to see the output

Search Zolo

9 results

enespt-br