Nested loops mean one loop runs inside another. To solve tracing questions, you must follow the program step by step and record what happens after each repetition.
Start with the first value of the outer loop. For that value, run the entire inner loop before moving to the next outer value. This is the key idea: the inner loop resets each time the outer loop repeats.
Write down the values of any counters, printed outputs, or updates in the exact order they occur. A table with rows for the outer loop and columns for the inner loop can help avoid skipping steps.
If the exercise asks for a final expression, combine like terms or reduce repeated additions after tracing all iterations. If the answer is a list of outputs, keep the order exactly as produced by the code.
Make sure each loop stops at the correct limit, the inner loop restarts correctly, and no iteration is counted twice. A good check is to compare the number of recorded steps with the total number of times the inner loop should run across all outer loop values.
© 2023-2026 AI MATH COACH