ABSTRACT

In Chapter , we saw that the logical ow of execution in a function or program is governed by three basic control mechanisms: sequence, selection, and repetition. We looked at examples where an if statement was used to perform selective execution and for and while statements to perform repetitive execution. Our introductions to these statements were quite brief, however, so we will take a closer look at them in this chapter and the next. We will begin by looking at the if statement in more detail and then introduce the switch statement that sometimes provides a more ecient way to perform selection. In Chapter 9, we will reexamine the for statement and see some of the other ways it can be used to control repetition. We will also introduce the do-while statement, and we will compare it with the while statement we studied in Chapter 5.