Вы находитесь на странице: 1из 3

As you know, one loop can be nested inside of another.

Nested loops are used to solve a


wide variety of programming problems and are an essential part of programming.

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.

Here's a portion of the output produced by the program.


Summary

In this lesson, you learned that loops may be nested.

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.

Вам также может понравиться