Overview
In Chapter 5, students learn how repetition structures are incorporated into programs.
Students will explore different types of loops, including counter-controlled, sentinel-
controlled, flag-controlled, and EOF–controlled loops. The three C++ repetition
structures will be introduced: while loops, for loops, and do…while loops. Students
will also examine the use of break and continue statements in loops. Finally, they
will learn how to incorporate nested repetition and selection structures into their
programs.
Objectives
In this chapter, the student will:
• Learn about repetition (looping) control structures
• Learn how to use a while loop in a program
• Explore how to construct and use counter-controlled, sentinel-controlled, flag-
controlled, and EOF–controlled repetition structures
• Learn how to use a for loop in a program
• Learn how to use a do…while loop in a program
• Examine break and continue statements
• Discover how to form and use nested control structures
• Learn how to avoid bugs by avoiding patches
• Learn how to debug loops
Teaching Tips
Why is Repetition Needed?
1. Explain why repetition structures are invaluable to a programming language. Discuss
why repeating a set of statements in a program using a loop is preferable to typing in the
statements over and over.
Students may have felt somewhat limited with previous programming
assignments because of the inability to use several sets of input. Discuss how
programs from previous chapters, such as the Calculator program, could be
enhanced with repetition structures.