AP® Computer Science A glossary

Nested iteration

Also called: nested loops

Course: AP® Computer Science A Shows up in: Unit 2: Selection and Iteration

A loop inside the body of another loop. The inner loop completes all its iterations before the outer loop continues to its next iteration.

Appears in the course and exam description (CED): 2.11.A.1

With fixed bounds, the inner body runs (outer iterations) times (inner iterations). Use a different loop control variable for each loop.

for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= i; j++) {
        System.out.print("*");
    }
    System.out.println();
}

Output:

*
**
***
Learn it properly, with a checkpoint 2.11 Nested Iteration

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure