Chapter 6Repetition

How do you make a computer do the same thing over and over again? Surely you don’t have to type the code multiple times, right?

According to the structured program theorem, you can use three basic control structures to solve problems with computer programs: sequencing, selection, and repetition. Sequencing is a fancy way of saying that you need to process one step after another in the right order. And selection is making decisions based on conditions. We’ve done both of these throughout the book already. Our early programs did a lot of sequencing, and then we moved into selection when we had our programs start making decisions based on conditions.

But in order to repeat parts of our programs without duplicating code, we use ...

Get Exercises for Programmers 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.