Unit 2 · Selection and Iteration
Nested Loops
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What nested loops covers
In nested loops the inner loop completes all of its iterations for every single iteration of the outer loop. When both bounds are fixed, the total iteration count is the product of the two. When the inner bound depends on the outer variable, as in for (int j = 0; j < i; j++), the pattern becomes triangular and the total is a running sum rather than a product.
Where students lose points
The biggest error is resetting or failing to reset the inner variable, which throws off every traced value. Students also add the two loop counts instead of multiplying them, and they miscount triangular patterns by assuming the inner loop always runs the same number of times.
How it shows up on the AP exam
Unit 2 iteration that becomes essential in Unit 4 for 2D arrays. Output-pattern questions and iteration-count questions are both standard MCQ formats built directly on this topic.
For practice use only.
Nested Loops MCQ Practice
AP CSA nested loop practice: counting total iterations, tracing inner and outer variables, and triangular patterns where inner bounds depend on the outer index.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class NestedLoopsContext
{
public static void runExample()
{
for (int r = 1; r <= 2; r++)
{
for (int c = 1; c <= 3; c++)
{
System.out.print(r);
}
}
}
public static void main(String[] args)
{
runExample();
}
}