Overview
Iterative Fibonacci builds up the sequence using two variables, no recursion needed.
Analogy
Leapfrog: always remember only the last two steps you took.
Step-by-step
- Start with a=0, b=1.
- Loop n-1 times: a, b = b, a+b.
- After the loop, a holds fib(n).
Visual
a=0,b=1 → a=1,b=1 → a=1,b=2 → a=2,b=3 → a=3,b=5
Common mistakes
- Off-by-one in loop count.
- Using a list to store all values when only the last two are needed.
Practice questions
- Print the first 20 Fibonacci numbers.
- Find the first Fibonacci number > 1000.