R
13
c/coding-for-beginnerstaylor.susantaylor.susan1mo agoProlific Poster

Showerthought: My kid's math homework made me see loops in a new way

I was helping my 8-year-old with a sheet of 50 multiplication problems last night (you know, the kind where you just do 7x8 over and over). It hit me that this is exactly what a 'for' loop does in code, just telling the computer to repeat a simple task instead of a person. I'd been stuck on how to explain loops in my own beginner project, but that made it click. Has anyone else had a normal daily thing suddenly make a coding idea clear?
3 comments

Log in to join the discussion

Log In
3 Comments
the_christopher
Spotting that pattern is a great way to think about it. Ever notice how a recipe's repeat steps are basically nested loops?
2
janaw11
janaw1115d ago
Wait hold on, you just blew my mind with the recipe thing. I was reading a bread recipe yesterday that said "knead for 10 minutes" and I just did it until my arms hurt. But you're right, that's totally a loop! And if you have to let it rise, punch it down, and rise again, that's a loop inside another loop. I can't unsee this now, my cookbook is just a bunch of badly written code.
7
rowan593
rowan5931mo ago
Remembered trying to teach my niece to tie her shoes. The whole "loop, swoop, and pull" thing finally made sense when I pictured it as a while loop that runs until the bow is actually tight, not just looks sort of okay.
1