Unable to open this exercise
A dry run follows an algorithm manually, tracking variables, condition results and output. Use the row convention stated in the task. Some tables record each change; others request snapshots at particular points. Do not invent a universal marking penalty for repeated values.
Worked snapshots
This example records initial values, then a snapshot after each complete loop body, followed by output. Unchanged values repeat because these are snapshots.
DECLARE Sum, Count : INTEGER
Sum <- 0
Count <- 1
WHILE Count <= 3 DO
Sum <- Sum + Count
Count <- Count + 1
ENDWHILE
OUTPUT Sum
Event | Count | Sum | Output |
|---|---|---|---|
Initialisation | 1 | 0 | |
After iteration 1 | 2 | 1 | |
After iteration 2 | 3 | 3 | |
After iteration 3 | 4 | 6 | |
Final output | 4 | 6 | 6 |
At Count = 4, the condition is false so the body does not run again. The update to Count happens after adding it to Sum, which explains why the first post-body row has Count = 2 but Sum = 1.
For a change-only table, record each assignment when it occurs and leave unaffected cells empty. Always preserve earlier entries, include initialisation where requested and record output exactly. Trace the exercises before using the interpreter to check your reasoning.
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Concept Check: Trace order
Concept Check: Trace order
- Starting with Sum=0 and Count=1, execute Sum <- Sum + Count then Count <- Count + 1. Sum is: [Space 1]
- Count is: [Space 2]
Interactive exercises for Module 2 and beyond require an active plan.