|
|
Solving problems on a computer very often requires a repetition of a block of code. Reading in data from a file, outputting to a file or adding numbers are situations where repetition is required. In Lesson A9, Recursion, we have already explored repeating code. However, not all iterative problems lend themselves to recursive solutions. Java provides three alternative constructs for repeating code with the for loop, the while loop, and the do-while loop. The while and for control structures allow us to set up a conditional loop, one that occurs for an indefinite period of time until some condition becomes false. We will also study the optional do-while loop and the concept of nested loops.
The key topics for this lesson are:
- The while Loop
- Loop Boundaries
- Conditional Loop Strategies
- The for Loop
- Nested Loops
- The do-while Loop (optional)
- Choosing a Loop Control Structure
- Loop Invariants
|