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, it 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 another. ...