💡
12
c/coding-for-beginners•ellis.faithellis.faith•2mo agoProlific Poster

I was sure my for loop was broken because it kept running forever

Turns out I was incrementing the wrong variable inside the loop, so the condition was never met. I spent an hour staring at it before a friend spotted my mistake. Has anyone else done something that simple and felt completely stuck?
4 comments

Log in to join the discussion

Log In
4 Comments
lee847
lee8472mo ago
What variable were you trying to increment instead? I've definitely written 'i++' when the loop used 'x' and just sat there baffled lol. Those tiny typos are the worst.
2
avery_ross
avery_ross1mo ago
Disagree, those little typos teach you to read your code twice which makes you a better debugger in the long run.
4
the_drew
the_drew2mo ago
Wait, did you mean you wrote i++ when the loop variable was x? I've done the opposite before, like using the right variable name but spelling it wrong. One time I had a loop with "counter" and kept typing "count++" instead. It compiled fine and just ran forever. How do our brains just skip over those details after looking at code too long?
2
sage308
sage3082mo ago
Ugh, those are the absolute worst (like when you're so sure the code is broken, but it's just your own tiny mistake). I swear the more you stare at it, the more invisible it gets.
1