In this chapter, we completed our introduction to C++'s control statements, which enable programmers to control the flow of execution in functions. Chapter 4 discussed the if, if...else and while statements. The current chapter demonstrated C++'s remaining control statementsfor, do...while and switch. We have shown that any algorithm can be developed using combinations of the sequence structure (i.e., statements listed in the order in which they should execute), the three types of selection statementsif, if...else and switchand the three types of repetition statementswhile, do...while and for. In this chapter and Chapter 4, we have discussed how programmers can combine these building blocks to utilize proven program construction and problem-solving techniques. This chapter also introduced C++'s logical operators, which enable programmers to use more complex conditional expressions in control statements. Finally, we examined the common errors of confusing the equality and assignment operators and provided suggestions for avoiding these errors.
In Chapter 3, we introduced C++ programming with the basic concepts of objects, classes and member functions. Chapter 4 and this chapter provided a thorough introduction to the types of control statements that programmers typically use to specify program logic in functions. In Chapter 6, we examine functions in greater depth.