GCSE · Computer Science · AQA · Spec 8525
Iteration
Two loops. Same job. Same starting value. One runs its body zero times and the other runs it once, and the only difference is where the question gets asked.
Computer Science · Iteration
Same job, same start, different answer
Two loops that both try to charge a battery until it is full. The battery is already full. Step through and keep your eye on the highlighted line.
Before you press Next: how many times will each loop body run, 0 or 1?
1 # Version A: the question comes FIRST2 battery ← 1003 passes ← 04 WHILE battery < 1005 battery ← battery + 206 passes ← passes + 17 ENDWHILE8 OUTPUT passes9 # Version B: the question comes LAST10 battery ← 10011 passes ← 012 REPEAT13 battery ← battery + 2014 passes ← passes + 115 UNTIL battery ≥ 10016 OUTPUT passes
Variables
Output
Step 1: Version A starts with a battery that is already full: 100.
Press Next and watch the highlighted line. Does it reach the loop's question before the body, or after it?
Computer Science · Iteration
Which kind of loop is it?
Which kind of loop fits each one best?
Still to sort
Definite (count-controlled) (0)
Runs a set number of times, known before the loop starts.
Where the line is: If the number of passes depends on something that happens inside the loop, it is not definite.
Indefinite: condition at the start (0)
Repeats on a condition that is checked before the body.
Where the line is: Look at WHERE the condition is written, not which keyword you can see.
Indefinite: condition at the end (0)
Repeats on a condition that is checked after the body.
Where the line is: Look at WHERE the condition is written, not which keyword you can see.
You've just met two loops that repeat on a condition. There's also a loop that simply counts. Some of these are loop headers and some are jobs a program has to do: place each one, then read why.
AQA 8525: you need to understand loops with the condition at either end, even if the programming language you use only has one of them.
Computer Science · Algorithms
Trace table — dry run the code
A loop inside a loop: 2 rows of 3 seats. Will count finish on 5 or 6? Step through and watch seat each time a new row starts.
Ready when you are — step through one line at a time.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Count-controlled and condition-controlled loops, and why the place a condition sits changes what a program does
What you need to know
- The difference between definite (count-controlled) and indefinite (condition-controlled) iteration, and how to choose between them.
- What changes when a loop's condition is checked at the start rather than at the end.
- How REPEAT … UNTIL and DO … WHILE stop, and why UNTIL is not the same as WHILE.
- How to trace a nested loop, and how to write algorithms that combine loops with other statements.
The big picture
Iteration means repeating instructions with a loop. A count-controlled (definite) loop such as FOR i ← 1 TO 5 runs a number of times known before it starts, while a condition-controlled (indefinite) loop repeats until a condition says stop. Checked at the start (WHILE), the body might never run; checked at the end (REPEAT … UNTIL or DO … WHILE), it always runs at least once, and UNTIL stops when its condition becomes true. Loops can nest inside each other and combine with assignments, constants and IF statements, so every program is built from sequence, selection and iteration.
Key points
Worked example
Problem
Write an algorithm that asks for a whole number, keeps halving it (using DIV 2) until it gets down to 1, and outputs how many halvings that took. If the number typed is already 1, it should output 0.
⚠ Watch out
Reading UNTIL as if it meant WHILE. REPEAT … UNTIL Solved stops as soon as Solved becomes true. It does not keep going while Solved is true.
Memory hook
WHILE looks before it leaps. REPEAT leaps, then looks.
Check yourself
Cover the page and answer out loud: when would you choose a FOR loop, a WHILE loop, and a REPEAT … UNTIL loop? Give one task that suits each.
Flashcards
(13)What is iteration?
What is definite (count-controlled) iteration?
What is indefinite (condition-controlled) iteration?
FOR or a condition-controlled loop: what's the deciding question?
WHILE NotSolved … ENDWHILE: where is the condition checked?
REPEAT … UNTIL Solved: where is the condition checked?
When does REPEAT … UNTIL Solved stop?
Which loop does the same job as REPEAT … UNTIL Solved?
DO … WHILE contains the word WHILE. Is it start-checked?
When should the condition go at the end of a loop?
What is nested iteration?
In a nested loop, what happens to the inner loop on each pass of the outer loop?
What are the three ways statements are combined in high-level imperative programs?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
- Greater than or equal to (relational operator)
- Identifying and categorising errors
- Indefinite (condition-controlled) iteration
- Integer / real to string conversion
- Integer data type
- Integer division and remainder
- Keyboard input
- Less than (relational operator)
- Less than or equal to (relational operator)
- Local variables
- Logic errors
- Meaningful identifier names
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 8 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.