6
The one YouTube shortcut that actually fixed my broken loop
I kept getting stuck in infinite loops in Python and spent hours staring at my screen until I found a short video showing me to print the loop variable at each step, which instantly showed me my counter was resetting to zero every time, has anyone else had a dumb bug that was this simple to fix?
2 comments
Log in to join the discussion
Log In2 Comments
ericj4513d ago
Show us the exact line where you printed the variable...
6
mila_campbell2511d ago
oh wait actually that's not quite right. you don't have to show the exact line where you printed the variable. honestly just printing it anywhere in the loop is enough to spot the problem. the trick is you gotta print it at the start of the loop so you can see what it's doing each time. if it resets to zero you'll see it right away in the output. i've done the same thing where i had a variable that was supposed to count up but i accidentally set it back to zero inside the loop. drove me crazy for an hour until i did exactly that. the point is you don't need to be super specific about where you put the print statement, just get it in there somewhere that makes sense.
2