Iteration (Loops)
Practise Iteration (Loops) for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers for AQA GCSE Computer Science (8525). Iteration repeats code using count-controlled (for) or condition-controlled (while) loops.
Free downloads
These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.
Topic overview
Iteration means repeating a block of code. Two kinds must be known: count-controlled and condition-controlled.
A count-controlled loop repeats a fixed number of times, using FOR i ← 1 TO 10 ... ENDFOR. Use it when the number of repetitions is known in advance, such as processing every item in a list of known length.
A condition-controlled loop repeats while a condition holds. WHILE condition ... ENDWHILE tests before each iteration, so it may run zero times. REPEAT ... UNTIL condition tests after, so it always runs at least once. Choosing the wrong one produces an off-by-one error or an infinite loop, which is why the test position matters.
Revision notes
Count-controlled loops
FOR i ← 1 TO 10 ... ENDFOR repeats a fixed number of times.
Use when the number of repetitions is known in advance. The loop variable i is available inside the loop and increases automatically each iteration.
Condition-controlled loops
WHILE condition ... ENDWHILE tests the condition BEFORE each iteration, so the body may run zero times.
REPEAT ... UNTIL condition tests AFTER, so the body always runs at least once. This difference determines which to choose.
Avoiding infinite loops
A condition-controlled loop must contain something that can eventually make the condition False.
If a WHILE loop tests a variable that is never changed inside the loop, it runs forever. Checking that the loop can terminate is part of writing it.
Key points
- Iteration repeats a block of code.
- FOR loops repeat a fixed number of times.
- WHILE tests the condition before each iteration.
- A WHILE loop may run zero times.
- REPEAT UNTIL always runs at least once.
- The loop must be able to terminate.
Worked examples
Example 1
Write pseudocode using a FOR loop to output the numbers 1 to 5. [3 marks]
Working
Example 2
Explain the difference between a WHILE loop and a REPEAT UNTIL loop. [2 marks]
Working
Example 3
Explain how an infinite loop can occur in a WHILE loop. [2 marks]
Working
Common mistakes
Using a FOR loop when the count is unknown.
Use a condition-controlled loop instead.
Forgetting to change the loop variable in a WHILE loop.
This causes an infinite loop.
Confusing which loop tests first.
WHILE tests before; REPEAT UNTIL tests after.
Omitting ENDWHILE or ENDFOR.
Every loop must be closed.
Exam tips
- Choose the loop type by whether the count is known.
- Remember WHILE can run zero times.
- Check something inside the loop can end it.
- Close every loop with its matching keyword.
Key terms
- Iteration
- Repeating a block of code.
- Count-controlled
- A loop repeating a fixed number of times.
- Condition-controlled
- A loop repeating while a condition holds.
- Infinite loop
- A loop whose condition never becomes False.
Related topics
Written and reviewed against the current AQA specification. Spotted an error? Let us know.