6Going Loopy

Image

Nothing is worse than needing to do the same thing over and over. There’s a reason we’re told to count sheep when we’re having trouble falling asleep, and it has nothing to do with the amazing sleep-inducing powers of woolly mammals. It’s because endless repetition is boring, and your mind can drift off to sleep easily if you’re not focusing on something interesting.

Programmers don’t like repeating themselves either, unless they’re also trying to fall asleep. Thankfully, most programming languages have a for loop, which repeats things like statements and blocks of code automatically.

In this chapter, we’ll look at for loops, as well ...

Get Python for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.