Back to Grade 6

Coding: trace the program

Questions at easy, medium and hard levels. Pick a level and get a fresh set every time, with instant feedback.

Learn it Trace a program with a table: one column per variable, one row per step. Stop exactly when the loop's condition becomes false.

Example: n = 50, steps = 0. While n > 1: n = n ÷ 2 (drop remainder), steps = steps + 1.

  1. 50 → 25 → 12 → 6 → 3 → 1.
  2. That is 5 halvings.
  3. steps = 5.

Loading questions…