Results

Cambridge November 2026 results: AS & A Level on 7 January 2027, IGCSE and O Level on 14 January 2027.

Source: Cambridge International
STUDY GUIDE

AP CSA Nested Loops and Trace Tables

List each outer-loop value and the inner values visited for it. When the inner bound depends on the outer variable, the row lengths can vary.

Book your free 30-minute demo

Updated November 2026.

By LearnAllStudents Editorial Team. Source check dates are listed below.

Follow the worked example

For i from 0 through 3 and j from 0 while j < i, the visited pairs are none for i = 0; (1,0); (2,0),(2,1); and (3,0),(3,1),(3,2).

The total number of visits is 0 + 1 + 2 + 3 = 6. This is triangular rather than rectangular.

If each visit adds i + j, the contributions by outer row are 0, 1, 5 and 12, totalling 18.

Place the listing inside a Java class. Try the worked example’s inputs from its main method.

static int sumNestedPairs(int outerLimit) {
  int sum = 0;
  for (int i = 0; i <= outerLimit; i++) {
    for (int j = 0; j < i; j++) {
      sum += i + j;
    }
  }
  return sum;
}

Count the inner work separately for each outer step

When the end of the inner loop depends on the outer value, the number of visits can vary. List the inner count before summing. Then check what happens when the test changes from < to <= at the edge of each row.

Try it yourself

What is the number of visits if the outer range is i = 0 through 4 under the same rule?

Check your reasoning

0 + 1 + 2 + 3 + 4 = 10.

Use the idea in a different situation

What changes if j <= i replaces j < i?

Check the second task

One visit is added on each outer pass. For i = 0 through 4, the count becomes 15.

For parents

Ask, “Why does the first outer step produce no visits when j starts at 0 and must be less than i = 0?”

They should identify the failed condition before the first inner step and give the next row’s count.

Make a small grid of i and j. Cross out disallowed cells before counting the visited pairs.

How a tutor would approach this

Write down the expected output or state before running the Java code. Compare it with the actual output, trace where they first differ and test the fix against another input that arrives at the same kind of boundary.

Frequently asked questions

What mistake should I look for first?

Multiplying the outer count by the largest inner count counts combinations that never run.

How can I use this with a longer practice set?

Read the current course framework and official sample questions before deciding how to practise this technique in an exam-length task.

Are these official past-paper questions?

The worked example and practice tasks here are original. The sources section links to the official material for your course.

How can I tell if I can use the method on a new question?

Try the second task with the worked example covered. Explain which step needs to change and why before checking the answer.

Official sources

Related pages

Try a free 30-minute demo

Work through a question with a tutor. No payment needed.

Request a free 30-minute demo
YOUR NEXT STEP

A little clarity starts with 30 minutes.

Share your goals, explore a question and discuss a learning plan. Request your free 30-minute demo class — no payment needed. Tutor and time are confirmed separately.

Book your free 30-minute demo
Book free demoWhatsApp us