DEV Community


Discussion on: The Climbing Staircase Problem: How to Solve It, and Why the Fibonacci Numbers are Relevant

alisabaj profile image
Alisa Bajramovic Author

Hi Harry,
"For loops" are great for if you want to do something a certain number of times. In this case, we wanted to alter the variables first, second, and current until we reached the number n (which is the input value). For loops have this syntax where you declare a variable (in this case, i), initialize its starting index (in this case, 2), set its condition to keep executing (in this case, keep executing as long as i < n), and state how the variable will be updated each time we go through the loop (in this case, i increments every time we go through the loop). The syntax i++ is the shorthand for i = i + 1. You can find a longer explanation here. Hope this helps!

stemdeafteacher profile image
Harry Wood

Ah, I think I understand now. It's sort of like a counter ?