Computer science · Grades 6–10
Trace algorithms step by step
Use explicit starting values and loop boundaries.
Learn the idea
State
Record variable values after each step.
Loop
A loop repeats a defined sequence according to a condition or range.
Bounds
Inclusive and exclusive endpoints produce different iteration counts.
Debug
A trace helps find where actual and intended behavior diverge.
Worked examples
Start x = 1. Repeat x = x + 2 exactly four times. What is x at the end?
The values are 3, 5, 7 and 9.
9
Why must a loop's stopping condition be specified?
Termination and iteration count depend on the condition.
It determines how many iterations occur.
Check your understanding
Start total = 0. Add 1, then 2, then 3. What is total?
A zero-indexed list has three entries. Which indices are valid?
- 1, 2, 3 only.
- 0, 1, 2, 3.
- 0, 1, 2.
Why is testing only one input insufficient for many algorithms?
Answers and marking notes
Answers and marking notes
- 6
0 + 1 + 2 + 3 = 6.
- 0, 1, 2.
Three entries beginning at zero end at index two.
- Boundary, empty and unusual cases may behave differently.
Test a range related to the requirements.
Further reading and review references
These are reference links, not copied exercises, institutional endorsement or proof of independent review.
Independent educational review required. Grade bands are approximate; these are not officially aligned curricula.