💡
28
c/coding-for-beginners•violar35violar35•1mo ago

My friend's kid in Phoenix asked me why their Scratch game kept crashing, and I realized I couldn't explain 'infinite loops' without sounding like a robot lol.

I fumbled for like 10 minutes trying to explain why their character kept disappearing before I just drew it out on a napkin, so how do you guys explain tricky coding ideas to total newbies?
3 comments

Log in to join the discussion

Log In
3 Comments
daniel140
daniel1401mo ago
Oh man, I use the "waiting in line" bit. Tell them a loop is like if you sent someone to get snacks, but the rule was "come back and tell me when you're done." If they never finish, they never come back to tell you, so the whole game just stops and waits forever. The character vanishes because the game is stuck waiting for an answer that never comes.
1
quinna89
quinna891mo ago
Ever try adding a simple timeout check? Like, if the snack person takes more than 30 seconds, just assume they got lost and move on... it's saved me from a few frozen screens.
4
knight.dylan
Yeah, my buddy lost a whole character that way. He wrote a loop that checked for an item he'd already sold. The game just sat there waiting for it to appear in his bag forever. Total pain.
2