CPS 6.3,4 Ramm - Fall 2000 - 9/20/00 #11
Chapt 5. Iteration with Programs and Classes
- Problem: Adder Program
- Add an unknown number of numbers
- When to quit
- Sentinel Value
-
while
or for ?
-
adder.cpp
- The Fence Post Problem
- Defining Constants
- Syntax:
-
const type identifier = value;
- Style: use all caps for identifier
- e.g. const double PI = 3.14159265;
- Iteration (post-tested)
- initialization
- loop body
- update
- loop test
- Pre-tested and Post-tested Loops
-
do-while Loop Syntax
- do
- {
- statement list
- } while ( test expression )
- Using the
do-while Loop
addwhile.cpp
-
break Statement
- Nested Loops
multable.cpp
- Nesting can be hidden by using function
- A look at the Balloon Class