GCSE · Computer Science · AQA · Spec 8525
Indefinite (condition-controlled) iteration
How many times should a program ask for a password? Nobody knows until the user gets it right, so you need a loop that stops when a condition says so.
Computer Science · Iteration
Watch the condition do the deciding
Step through this WHILE loop one line at a time. Keep an eye on the WHILE line: control keeps coming back up to it, and each time it asks, 'Shall I go round again?'
Before you press Next: how many numbers will this loop output?
1 n ← 102 WHILE n < 503 OUTPUT n4 n ← n * 25 ENDWHILE6 OUTPUT 'Done'
Variables
Output
Step 1: n starts at 10. Nothing has been checked yet.
Press Next and watch where the highlight goes after each doubling. It always climbs back to the WHILE line.
Predict, then check
Both loops have the same body: OUTPUT n, then n ← n * 2. Both start with n ← 80.
Loop A is WHILE n < 50 … ENDWHILE. Loop B is REPEAT … UNTIL n ≥ 50. Starting from n ← 80, how many times does each body run?
Computer Science · Algorithms
Trace table — dry run the code
A FOR loop sits inside a WHILE loop. Predict first: when total goes past 20 halfway through the second round, does the outer loop stop straight away?
Ready when you are — step through one line at a time.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- Indefinite (condition-controlled) iteration repeats until a condition says stop, so the number of passes depends on the data rather than being fixed before the loop starts.
- With the condition at the start (WHILE … ENDWHILE), the check happens before every pass, so the body can run zero times.
- With the condition at the end (REPEAT … UNTIL or DO … WHILE), the body runs first and is checked afterwards, so it always runs at least once.
- UNTIL stops when its condition is TRUE; WHILE carries on while its condition is TRUE. REPEAT … UNTIL Solved does the same job as DO … WHILE NotSolved.
- Loops can be nested: the inner loop runs right through, start to finish, on every pass of the outer loop. Loops also combine with constants, variables, assignment, selection and subroutines.
The big picture
A condition-controlled loop repeats until a condition tells it to stop, so the number of passes depends on the data rather than being fixed in advance. With the check at the start (WHILE … ENDWHILE) the body can run zero times; with the check at the end (REPEAT … UNTIL or DO … WHILE) it always runs at least once. UNTIL stops when its condition is true, while WHILE carries on while its condition is true. Loops can be nested, and they combine with constants, variables, assignment and selection to build real programs.
Key points
Worked example
Problem
Trace this algorithm and state exactly what it outputs. x ← 1 REPEAT x ← x * 3 OUTPUT x UNTIL x > 20
⚠ Watch out
Forgetting to change the tested variable inside the loop. If nothing can make the condition change as the loop runs, a loop that starts running never stops.
Memory hook
WHILE looks before it leaps; REPEAT leaps, then looks. And UNTIL is the impatient one: the moment its condition is TRUE, it's out.
Check yourself
count starts at 5. How many times does WHILE count < 3 … ENDWHILE run its body? And how many times would REPEAT … UNTIL count ≥ 3 run it?
Flashcards
(13)What is indefinite (condition-controlled) iteration?
WHILE … ENDWHILE: where is the condition, and what does that mean?
REPEAT … UNTIL: where is the condition, and when does it stop?
DO … WHILE: where is the condition, and when does it stop?
Which DO … WHILE loop does the same job as REPEAT … UNTIL Solved?
How often does a condition-controlled loop check its condition?
Why might a condition-controlled loop never stop?
What is nested iteration?
In a nested loop, when is the outer condition checked?
What are the three combining principles of high-level imperative programming?
Which other statement types can iteration be combined with in a program?
Do you need to understand checks at both ends of a loop if your language only has one kind?
When would you choose a condition-controlled loop over a count-controlled one?
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
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 30 September 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.