CPS 1 - Spring, 2000 - Ramm 2/7/00 #10
- Announce
- Continue to Read Course Pack Chapter 3
3. Numerical Computation and the Study of Functions
- Loops!! ... and it all happened again ...
- The
while Loop
- while (boolean expression)
- {
- statement;
- ...
- statement;
- }
- statements repeated as long as logical expression is true
- For proper loop: at least one of previous
statements must cause change in logical expression
- Looping Examples
- Summing the numbers 1 ... 100
- Gauss Story
- Code:
- int sum = 0;
- int k = 0;
- while (k < 100)
- {
- k = k + 1;
- sum = sum + k;
- }
- Looping Example
CompInterest.java,
CompInterest.html
- Looping Example
Diamond.java,
Diamond.html
- Other Loops Designs
- Count Down
- Starting and Stopping at Computed Values
- Data Dependent Loop
- Redesign of Diamond Program
- Variable Size
- Other Shapes
- Use of Magic Numbers