The Fibonacci sequence is a classic recursion example. Each number is the sum of the two before it:
func fib(n int) int {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
This works but is slow for large n because it recalculates the same values repeatedly. For fib(), you'll wait seconds. Later, you'll learn techniques to make this faster.