Chapter 4 - Control Structures - Repetition
Chapter 4 - Control Structures - Repetition
Hoboken,
NJ. All Rights Reserved.
Chapter 4
Control Structures:
Repetition
Outline
Objectives
1. Algorithm Development
2. Repetition Structures
3. Problem Solving Applied: GPS Data
4. C++ break and continue Statements
5. Structuring Input Loops
6. Problem Solving Applied: Weather Balloons
7. Building C++ Solutions with IDEs: Microsoft Visual C++
• Sequential structures
are not well suited for
computing the same
quantities repeatedly.
• This flow chart
describes repetition best
implemented with a
while statement.
• do while Statement
• for Statement
Examples
do
cin.get(ch); //statement repeated until
while (ch!=‘\n’) // newline character read
Examples
int sum=0;
for (int i = 1; i <= 10; i++)
sum += i;
cout << sum << endl;
…
int sum=0;
for (int i = 0; i < 10; ++i)
sum += i;
cout << sum << endl;