Dry Runs, Tracing & Logic Control: Following Variable Changes Line-By-Line (Copy)
Following Variable Changes Line-By-Line (Cambridge Standard – O Level 2210 + IGCSE 0478)
Why Line-By-Line Variable Tracking Is Critical In Paper 2
- Cambridge awards marks for:
- Correct execution order
- Correct intermediate variable values
- Many candidates:
- Jump to final values
- Skip intermediate assignments
- Paper 2 marking:
- Penalises skipped steps even if final output looks plausible
- Line-by-line tracking proves:
- Control flow understanding
- Assignment timing awareness
- Correct handling of loops, selection, and procedures
What “Line-By-Line” Means In Cambridge Terms
- Every statement is executed:
- In the order written
- Variable values:
- Change immediately after an assignment
- IF / ELSE:
- Only one branch executes
- Loops:
- Re-evaluate conditions before each iteration (WHILE / REPEAT)
- Automatically update index (FOR)
Golden Rule Of Variable Tracking
- The value of a variable changes only at assignment
- If no assignment occurs:
- The value remains unchanged
- Reading a variable:
- Does not change it
Step 1: List All Variables That Can Change
Before tracing, identify:
- Counters (count)
- Accumulators (total)
- Index variables (i, index)
- Flags (found, valid)
- Temporary variables (temp)
- Return variables (for functions)
Step 2: Write Initial Values Explicitly
- Initial values apply:
- Before the first executable line
- Common initialisations:
- total ← 0
- count ← 0
- found ← FALSE
- index ← lowerBound
If you skip this step:
- Every following value becomes incorrect
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 3: Follow Assignments One Line At A Time
Example Algorithm
- x ← 5
- y ← x + 2
- x ← y * 2
Line-By-Line Variable States
| Line Executed | x | y |
|---|---|---|
| x ← 5 | 5 | — |
| y ← x + 2 | 5 | 7 |
| x ← y * 2 | 14 | 7 |
Examiner Trap
- Using original x instead of updated x
- Forgetting assignment order
Step 4: Tracking Variables Inside IF Statements
Algorithm
- score ← 45
- IF score >= 50 THEN
- grade ← “P”
- ELSE
- grade ← “F”
- ENDIF
Execution Logic
- Condition evaluated:
- FALSE
- Only ELSE branch executes
- grade ← “F”
- grade does not change again
Key Rule
- Variables in non-executed branches:
- Do not change
Step 5: Tracking Variables In FOR Loops
FOR Loop Characteristics
- Index variable:
- Automatically updates
- Index should not be manually changed
- Assignments inside loop:
- Apply per iteration
Algorithm
- total ← 0
- FOR i ← 1 TO 3
- total ← total + i
- ENDFOR
Line-By-Line Execution
| Iteration | i | total before | total after |
|---|---|---|---|
| 1 | 1 | 0 | 1 |
| 2 | 2 | 1 | 3 |
| 3 | 3 | 3 | 6 |
Examiner Trap
- Adding i after loop
- Forgetting FOR end is inclusive
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 6: Tracking Variables In WHILE Loops
WHILE Loop Execution Order
- Condition checked
- Body executes if TRUE
- Variables updated inside body
- Condition checked again
Algorithm
- index ← 1
- total ← 0
- WHILE index <= 3 DO
- total ← total + index
- index ← index + 1
- ENDWHILE
Line-By-Line Table
| Step | index | total |
|---|---|---|
| Initial | 1 | 0 |
| Iteration 1 | 2 | 1 |
| Iteration 2 | 3 | 3 |
| Iteration 3 | 4 | 6 |
| Condition FALSE | 4 | 6 |
Examiner Trap
- Stopping when index = 3
- Forgetting final increment happens before condition check
Step 7: Tracking Variables In REPEAT UNTIL Loops
Key Difference From WHILE
- Body executes at least once
- Condition checked at the end
Algorithm
- count ← 0
- REPEAT
- count ← count + 1
- UNTIL count = 3
Execution
| Iteration | count |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| Stop (condition TRUE) | 3 |
Examiner Trap
- Treating REPEAT like WHILE
- Skipping first execution
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 8: Tracking Variables When Arrays Are Involved
Algorithm
- total ← 0
- FOR i ← 1 TO 4
- total ← total + values[i]
- ENDFOR
Rule
- At each iteration:
- values[i] is read
- total is updated
- values[] does not change unless explicitly assigned
Common Mistake
- Assuming reading values[i] modifies the array
Step 9: Tracking Variables With Temporary Variables
Algorithm
- temp ← values[i]
- IF temp < 0 THEN
- temp ← 0
- ENDIF
- values[i] ← temp
Execution Logic
- temp stores original value
- temp may change
- array updated only at final assignment
Examiner Focus
- temp changes do not affect array until assigned back
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 10: Tracking Variables Across Procedures And Functions
Procedure Call (No Return)
- x ← 5
- CALL increase(x)
If parameter is:
- Passed by value (Cambridge assumption):
- x outside does not change
Function Call (Return Value)
- x ← increase(x)
- Returned value replaces x
Examiner Trap
- Assuming procedure updates variables globally
- Ignoring return assignment for functions
Step 11: Tracking OUTPUT Statements Line-By-Line
- OUTPUT does not change variables
- It reports:
- Current values at that exact line
- If OUTPUT is inside a loop:
- Each iteration produces output
Common Variable-Tracking Errors Cambridge Penalises
- Using future values too early
- Ignoring assignment order
- Updating variables in non-executed branches
- Forgetting loop index updates
- Treating conditions as assignments
- Assuming values change without assignment
Examiner’s Mental Checklist (Adopt This)
- Has this variable been assigned yet?
- Did this assignment just occur?
- Has the loop condition been rechecked?
- Did this IF branch execute?
- Has the array been updated already?
Best-Practice Strategy Under Exam Conditions
- Draw a mini table even if not asked
- Update values immediately after assignment
- Never “hold” a value mentally
- Treat each line as atomic
- Pause after each assignment and update your table
Final Quality Checklist
- Initial values written
- Assignments followed exactly
- No skipped lines
- Loop conditions respected
- Updates applied immediately
- Outputs match execution point
Final Lock-In Rules
- Variables change only on assignment
- Order of lines matters
- Loops re-evaluate conditions correctly
- IF executes only one branch
- Line-by-line tracking = full Paper 2 control
