At a Glance
- Quick Quizzes
- Additional Resources
- Key Terms
Chapter 5 covers loops in detail. Students learn the advantages of looping. They also
learn to use a while loop and to control loops with sentinel values. Common loop
mistakes are covered in detail. Students are also introduced to the for loop, the do
while loop, and the do until loop. Finally, students learn how to use nested loops
and how to accumulate totals using loops.
In this chapter, your students will learn about:
- The advantages of looping
- Using a loop control variable
- Nested loops
- Avoiding common loop mistakes
- Using a for loop
- Common loop applications
Understanding the Advantages of Looping
1. Understand the advantages of using loops in a program.
2. Describe examples in which looping might be required, such as processing payroll
1. I the term loop control variable .
2. Explain the three actions required for a loop to end correctly.
3. Note that a loop’s repetition is controlled with either a counter or a sentinel value.
Using a Definite Loop with a Counter
1. Understand and explain the term definite loop . A definite loop is also called a counted
or counter-controlled loop .
2. Walk through the code example in Figure 5-3, pointing out the loop control variable and
explaining how it is used to control the number of repetitions of the loop.
3. Understand how to control a loop by incrementing or decrementing control variables.
4. Understand how the example in Figure 5-3 could be controlled by decrementing the
5. Discuss the concept of a counter .
6. Although many loops start with the counter set to zero, it is not required to do so.
Using an Indefinite Loop with a Sentinel Value
1. Understand what an indefinite loop is.
2. Walk through the example in Figure 5-4, pointing out how the loop is controlled by user
The sentinel value used to control a loop can be a variable whose value may change prior to
executing the loop itself.
Understanding the Loop in a Program’s Mainline Logic
1. Walk through the itemized list on page 190, which describes the three steps that must
occur in every loop.