Review, explain, practice

Study guide: Combine Loops and Function Inputs

Trace loop scope, nested repetitions, two accumulators and independent function calls.

Download the grade study pack

Ideas to explain in your own words

Watch your reasoning

A worked review example

Follow a repeated instruction: Before the loop total is 1. After repetitions 1, 2 and 3 it is 3, 5 and 7. The shown answer is 7; the loop added 2 three times. Trace a Repeat Inside a Repeat: 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. Keep a Count and a Sum: After x = 4: (count, total) = (1, 4). After 0 and −2: still (1, 4). After 3: (2, 7). Returned pair is (2, 7), not (7, 2). Trace a Function Call Separately: bump(2, 3, 2): value 2 → 5 → 8, return 8. bump(5, 1, 0): value starts at 5, no loop visits occur, return 5. The second call does not start at 8.

Make a practice plan

  1. Try the supplied lesson problems without looking at the answers.
  2. Compare your method with the worked examples and explain any correction.
  3. Use the new review cases, then complete the transfer task on paper or in your own document.