F
5
c/coding-for-beginnerssage_moore37sage_moore3711d agoMost Upvoted

I finally fixed my infinite loop bug at 2am

Was working on a project for a local library website. Simple contact form. Had a while loop checking form inputs. Ran the test script and my laptop fans went jet engine loud. Browser froze solid. Had to hard reboot the machine. Forgot to add a break condition in the loop. Stupid mistake but I stared at the code for 45 minutes before seeing it. The fix was literally typing 'break' on one line. Felt like a genius and an idiot at the same time. Anyone else waste hours on a one word fix?
3 comments

Log in to join the discussion

Log In
3 Comments
shane_park92
Pulled an all nighter once myself @king.eric. Had a PHP script that just ran and ran until the server timed out. Turned out I was using a while true loop but never told it when to stop. Stared at that thing for hours before my buddy pointed out I needed a counter variable going up with each loop. Felt like a complete moron when he just wrote $i++ on the same line as my condition and it worked perfect.
2
king.eric
king.eric11d ago
Dude, you ever have a buddy tell you about a bug and you just know you would have made the same mistake? My friend Mike was building a simple score tracker for his bowling league. He spent three hours debugging a loop that kept resetting his high score to zero. Turns out he was updating the score variable inside the if statement instead of the loop condition itself. The fix was moving a single curly brace one line down. He said he almost threw his keyboard through the monitor when he saw it. Sometimes the dumbest little thing makes you feel like a total hack. But hey, at least you caught it before the library staff had to deal with a broken form.
0
irisowens
irisowens9d ago
Oh man, totally feel you on that @king.eric. "One curly brace one line down" is the kind of thing that makes you question your whole life choices lol. I had a similar moment where I spent like two hours trying to figure out why my form validation was breaking. Turns out I had an extra semicolon after my if statement condition, so the block underneath just ran every time no matter what. My friend just looked at it and was like "uh, that semicolon shouldn't be there" and I wanted to crawl under my desk. It's always the dumbest stuff that makes you feel like you've never coded before in your life.
4