Chapter 05
Chapter 05
5.8 Sentinels
5.9 Deciding Which Loop to Use
5.10 Nested Loops
5.11 Breaking Out of a Loop
5.12 Using Files for Data Storage
5.13 Creating Good Test Data
false
condition
true
statement(s)
x = ++y; // y is incremented to 2
// Then 2 is assigned to x
cout << x
<< " " << y; // Displays 2 2
x = --y; // y is decremented to 1
// Then 1 is assigned to x
cout << x
<< " " << y; // Displays 1 1
statement(s)
true
condition
false
do {
// code to display menu
// and perform actions
cout << "Another choice? (Y/N) ";
} while (choice =='Y'||choice =='y');
initialization
code
update
code
false
test
true
statement(s)
int total = 0;
cout << "Enter points earned "
<< "(or -1 to quit): ";
cin >> points;
while (points != -1) // -1 is the sentinel
{
total += points;
cout << "Enter points earned: ";
cin >> points;
}
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-
Wesley 5-37
5.9 Deciding Which Loop to Use