O
16

I kept messing up my loops and a weird trick finally fixed it

For like a month, I couldn't get my head around nested loops in Python, they just kept running forever. I was trying to make a simple times table generator and it kept crashing. Then I saw a tip on a forum to physically write out the variable values on a piece of paper for each step, like 'i=1, j=1, print 1'. Did that for 15 minutes and it finally clicked how the inner loop resets. Has anyone else found a simple, non-computer trick that helped them get a coding concept?
2 comments

Log in to join the discussion

Log In
2 Comments
grant826
grant8267d ago
Totally get that. Rubber duck debugging is the classic version of this. You just talk your code out loud to a rubber duck on your desk. Explaining the problem step by step forces your brain to slow down and catch the logic errors. I've done it with a coffee mug when I couldn't find a bug in a simple function. Saying "okay, so first we take this number..." makes the mistake obvious. Physical stuff just makes abstract ideas click.
6
ryanj60
ryanj607d ago
Remember trying to learn recursion and feeling totally lost. I grabbed a deck of cards and tried to sort it by splitting the pile in half over and over, explaining each step out loud to my dog. Actually moving the physical cards made the whole "base case" thing make sense in a way staring at code never did.
2