Professional Documents
Culture Documents
3.10. Nested Loops
3.10. Nested Loops
So, before leaving the topic of Java's loop statements, let's look at one more nested loop
example.
The following program uses a nested for loop to find the factors of the numbers from 2 to
100.
In the FindFac program, the outer loop runs i from 2 through 100.
The inner loop successively tests all numbers from 2 up to i, printing those that evenly
divide i.
You also learned that the nested loops are an essential part of any program and can be
used to solve a wide variety of programming problems.