Skip to content

Instantly share code, notes, and snippets.

@RussellAndrewEdson
Created January 4, 2015 03:31
Show Gist options
  • Save RussellAndrewEdson/f4af5aa8119190a9d98c to your computer and use it in GitHub Desktop.
Save RussellAndrewEdson/f4af5aa8119190a9d98c to your computer and use it in GitHub Desktop.
Python code to generate the nth Fibonacci number iteratively.
# Calculates the nth Fibonacci number using an iterative process.
def fibonacci(n):
(current, next) = (0, 1)
index = 0
while (index < n):
(current, next) = (next, current + next)
index += 1
return current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment