Apparently the following Python function
def fib(n):
a, b = 0, 1
while n > 0:
a, b, n = b, a+b, n-1
return b
Can return the nth Fibonacci
number. But how exactly does the while
loop above work? Can someone walk me through how the code above is able to give fib(4) = 3
?
Thank you.