DSE ICT | Programming: Loops and Debugging Lesson-Prep Guide (Tutor Edition) | for Traces, while Conditions, Fault Finding
- 2026-11-01
Students can read code but freeze when asked what the variable holds after the fifth pass. This lesson makes them write a trace table, then debug from the table.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Variables | After x = 3 then x = 5, what is x | 5, the old value is overwritten |
| Squares | The square of 4 | 16 |
| Comparison | When is n < 100 false | When n is 100 or more |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-8 min | Trace table format | Columns: pass, i, variable, test | Draw an empty table |
| 8-24 min | for loop trace | range(1,6) runs 1 to 5, add squares | Reach a total of 55 |
| 24-36 min | while loop | Double from 3, find the exit test | 6 passes, ending at 192 |
| 36-48 min | Three fault types | One fault in input, processing, output | Check each part |
| 48-56 min | Fix and rerun | Correct the loop, trace it aloud | Oral execution |
| 56-60 min | Exit check | Three questions marked on the spot | Independent work |
03 Teaching script (read it out)
Scene 1: for loops: trust the table, not your head
t = 0 then for i in range(1, 6): t = t + i*i. range(1,6) stops at 5, so there are five passes: 1+4+9+16+25 = 55. Each row of the table records i, i*i and t. Asked for t after the third pass, read row three: 14. No mental simulation needed.Ask the student: how many passes does range(1,6) give (five).
Scene 2: while loops: ask when it stops, not what it does
n = 3 then while n < 100: n = n * 2. The test comes first each time: 3, 6, 12, 24, 48, 96, 192. Since 96 is still below 100 the loop runs once more to 192, then the test fails, so there are 6 passes.Warn: students stop at 96. The condition is below 100, and 96 still satisfies it.
Ask the student: is the test checked before or after the body (before).
Scene 3: Debugging: split the program, then print the variables
Ask the student: what do you compare to find the faulty pass (the trace table).
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Trace | Value of t after the third pass | Fill the table row by row | 14 (1+4+9) |
| Count | Doublings from 3 to pass 100 | Test before each pass | 6 passes, ending 192 |
| Debug | Output one short of expectation | Check the range upper bound | range excludes the bound |
| Rewrite | Turn a while into a for | Use a for when the count is known | for k in range(6) |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| Sum of squares from 1 to 5 | 55 | Six not included |
| Final value doubling 3 until at least 100 | 192 | Stopped at 96 |
| Multiples of 3 between 1 and 20 | 6 | 18 counted once |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Range bound included | Adds 6 squared | range stops before the upper bound, so it ends at 5. |
| while stopped early | Treats 96 as the answer | 96 is still below 100, so one more pass is needed. |
| Accumulator not reset | Starts t from the previous question | Set t back to 0 before each new total. |
| No intermediate printing | Edits numbers until it looks right | Print inside the loop and find the first wrong pass. |
07 Homework (paper, section and question numbers)
- Secondary ICT chapter index — All chapters: data, networks, databases
- Secondary lesson-prep overview — All subjects
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| Sum of squares 1 to 5 | 55 | All three right: move to arrays |
| Passes doubling 3 | 6 | One wrong: reteach test ordering |
| Passes for range(1,6) | five | Two or more wrong: return to act one |
09 Tutor FAQ
Must we use Python?
The exam uses pseudocode, but tracing in Python builds the same habit fastest.
How long should a trace table be?
Long enough to answer the question, usually five or six rows.
How is an infinite loop answered?
Name the missing update or the always-true test, and write the corrected line.
Find a tutor — freeTutor Registration →
A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.


