T
24

My friend's kid asked me to explain what a 'for loop' does while we were waiting for pizza.

I told him it's like giving the same instruction to everyone in a line, one by one, and now I'm wondering if that's actually a good way to teach the concept to someone who's never seen code before.
3 comments

Log in to join the discussion

Log In
3 Comments
oscar_hunt61
oscar_hunt611mo agoMost Upvoted
Maxm50 makes a good point about the repetition count. I like the line idea a bit more if you say you're telling that one person to take a step and then check their number until they hit the right count.
8
maxm50
maxm501mo ago
That "line" idea is okay, but it misses the key part about doing something a set number of times. A real for loop is more like telling one person to take three steps, not telling three people to each take one step.
3
parker_bailey
parker_bailey1mo agoTop Commenter
But what if you have three people? The line idea works for that case. It just depends on what you're trying to do.
9