Chapter 6
Controlling Program Flow with Loops
IN THIS CHAPTER
Using basic looping
Counting as you loop
Repeating relentlessly (until the user gives you a clear answer)
In 1966, the company that brings you Head & Shoulders shampoo made history. On the back of the bottle, the directions for using the shampoo read, “LATHER–RINSE–REPEAT.” Never before had a complete set of directions (for doing anything, let alone shampooing your hair) been summarized so succinctly. People in the direction-writing business hailed this as a monumental achievement. Directions like these stood in stark contrast to others of the time. (For instance, the first sentence on a can of bug spray read, “Turn this can so that it points away from your face.” Duh!)
Aside from their brevity, the thing that made the Head & Shoulders directions so cool was that, with three simple words, they managed to capture a notion that’s at the heart of all instruction-giving: the notion of repetition. That last word, REPEAT, took an otherwise bland instructional drone and turned it into a sophisticated recipe for action.
The fundamental idea is that when you’re following directions, you don’t just follow one instruction after ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access