Lesson overview
Use condition-controlled loops when repetition depends on a true or false test.
Focus: Condition-controlled loops.
What you will learn
- Explain when a condition-controlled loop is suitable.
- Use a while-style condition to continue repetition.
- Update values so a loop can eventually stop.
- Trace loop behaviour with different test data.
Before you start
- Boolean conditions.
- Variables and assignment.
- Trace tables.
Repeat-until-ready scenarios
Use password attempts, menu choices and input validation examples to practise condition-controlled loops.
Condition-controlled loops infographic

Explanation
A condition-controlled loop repeats while a condition says it should continue, or until a condition says it should stop.
This is useful when the number of repeats is not known in advance. For example, a program may keep asking until the user enters a valid option.
Every condition-controlled loop needs a way for the condition to change. Otherwise the loop may never finish.
Worked examples
Asking for a valid age
INPUT age
WHILE age < 0
OUTPUT 'Enter a valid age'
INPUT age
Answer: The loop continues only while the entered age is invalid.
Quick checks
1. Which task suits a condition-controlled loop?
- a. Output exactly 5 stars
- b. Calculate one area
- c. Keep asking until a valid menu option is entered
Reveal answer
Answer: c. Correct. The number of repeats is not known in advance.
Not quite. Look for repetition based on a condition.
2. What can happen if the loop condition never changes?
- a. The loop may never finish
- b. The program automatically becomes faster
- c. The condition becomes a string
Reveal answer
Answer: a. Correct. This is an infinite-loop risk.
Not quite. Think about how the loop stops.
Practice
1. Why might password entry use a condition-controlled loop?
Reveal answer
Answer: The program does not know how many attempts will be needed.
Marking: Credit unknown repeat count.
2. In WHILE choice != 'Q', what should happen inside the loop?
Reveal answer
Answer: The program should eventually ask for or update choice again.
Marking: Credit updating the condition variable.
3. Give one way to reduce infinite-loop risk.
Reveal answer
Answer: Update the loop variable, use a clear stopping condition or limit attempts.
Marking: Credit any valid prevention.
4. What test data should you try for an input-validation loop?
Reveal answer
Answer: Invalid data, valid data and boundary values where relevant.
Marking: Credit testing both loop and exit behaviour.
Exam practice ladder
- Fluency: recall the key term and use it accurately.
- Application: apply the idea to the scenario rather than giving a generic definition.
- Algorithmic reasoning: show the steps, condition or variable change clearly.
- Evaluation: explain why one method, structure or control is suitable.
Answers and marking guidance
Exact answers and marking guidance are hidden under each question. For this lesson, earn marks by naming the correct Computer Science idea, applying it to the scenario and showing the logic or value change clearly.
Common mistakes
- Forgetting to update the value used in the condition.
- Using the wrong comparison so the loop stops too early.
- Writing a condition that is always true.
- Not testing the case where the loop should run zero times.
Extension
Design a loop that keeps asking for a number between 1 and 10 until the input is valid.
Next lesson
Next, continue with Lists, Arrays and Strings.
Exam-board guidance
Aplailasain is an independent learning resource and is not endorsed by any exam board.
AQA GCSE Computer Science
AQA GCSE Computer Science: this skill supports problem solving, clear algorithms and accurate programming explanations.
OCR GCSE Computer Science
OCR GCSE Computer Science: expect precise algorithm reasoning, trace work and careful use of programming vocabulary.
Pearson Edexcel GCSE Computer Science
Pearson Edexcel GCSE Computer Science: practise explaining the method as well as giving the final answer or code.
Eduqas GCSE Computer Science
Eduqas GCSE Computer Science: secure the transferable idea first, then check how your class applies it in tasks.
WJEC Wales
WJEC Wales: use accurate terminology and show enough working for the examiner to follow your logic.
CCEA
CCEA: connect the idea to your class route and use the same algorithm, programming or systems vocabulary your teacher uses.