Trace a Repeat Inside a Repeat
Distinguish outer iterations, inner iterations and initialization scope.
Supplied materials
- Paper and pencil; an adult may read aloud. No device, account or purchase is needed.
Learn the idea
A nested loop runs one loop inside another. Each outer iteration starts a complete inner loop. Keep separate counters for the outer and inner positions so every visit is visible. Here repeat exactly means a fixed number of repetitions, and total is initialized only once before either loop.
Pseudocode: total = 0; repeat 2 times: repeat 3 times: total = total + 1; after both loops, show total. The inner addition runs three times in the first outer iteration and three times in the second. If the initialization were moved inside the outer loop, the earlier group’s total would be erased.
- Make columns outer iteration, inner iteration and total.
- Start total = 0 before the first row.
- Write rows (1,1), (1,2), (1,3), (2,1), (2,2), (2,3).
- Add 1 per row and compare the six visits with 2 × 3.
See the method in action
The six rows end with totals 1, 2, 3, 4, 5, 6. Shown result: 6. With total = 0 moved just inside the outer loop, each outer group ends at 3 and the final result is 3.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
See the answer and explanation
12
There are 3 × 2 = 6 inner visits, each adding 2; the total is 12.
Take it further
Change only the original outer repeat count to 4. Expected inner visits: 4 × 3 = 12; final total 12.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.