Nested Loops
A Programming Pattern
Prof. David Bernstein
James Madison University
Computer Science Department
bernstdh@jmu.edu
Nested Loops
An Observation:
The statement (or block statement) that constitutes the body of the loop can contain a loop
Terminology:
Such loops are said to be "nested"
Common Uses of Nested Loops
Creating:
Prompting for valid input within another loop (this is not normally thought of as nested loops)
To create a "table"
Calculating:
To search for a value in a "table"
"Generate and Test" algorithms (i.e., generate candidates and see if they satisfy a condition)
Creating a Table
An Example
javaexamples/programmingpatterns/AdditionTableExample.java
(Fragment: 0)