Run a loop at least once
Use REPEAT…UNTIL when the body must run before the stop condition is tested.
Section 8 · Programming
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers section 8.1 (Programming concepts) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding.
Before you begin
- Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Does a REPEAT body run when the stop condition would already be true?
What you will learn
- Recognise post-condition iteration
- Write the stop condition correctly
- Explain why the body always runs at least once
REPEAT checks after the body
A post-condition loop executes its statements first, then tests the UNTIL condition. Therefore its body runs at least once.
UNTIL stops when the condition becomes TRUE. This is the opposite wording from WHILE, which continues while its condition remains TRUE.
Read the condition as a stop rule
For input validation, repeat asking while the value is unsuitable, then stop UNTIL it is in range. Use parentheses and a clear Boolean expression for two-sided boundaries.
Update the condition's variables during the body. If the stop condition never becomes true, the loop will continue indefinitely.
Pause and explain
A loop should stop after a valid age from 0 to 120 is entered. Which stop condition is correct?
Worked example
Keep asking for a rating until the user enters a value from 1 to 5 inclusive.
Show the worked solution
- Read Rating once in the loop body.
- The loop should stop when Rating >= 1 AND Rating <= 5.
- Invalid values cause another pass; a valid value ends the loop.
Answer REPEAT OUTPUT "Enter a rating from 1 to 5" INPUT Rating UNTIL (Rating >= 1) AND (Rating <= 5)
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
A REPEAT loop reads Number and stops UNTIL Number = 0. What happens if the first value is 0?
Give me a hint
The input has already been read once before testing.
Compare my reasoning
- The body prompts and reads 0.
- The condition is checked after the read.
- The loop stops after one pass.
The body runs once, reads 0, then the loop stops.
Look for these in your work
- Order identified
- At-least-once result
Write a REPEAT loop that asks again until PIN is exactly four characters long.
Give me a hint
The stop condition is the valid case.
Compare my reasoning
- Read PIN inside the loop.
- Check LENGTH(PIN) = 4.
- The loop stops when that equality is true.
REPEAT INPUT PIN UNTIL LENGTH(PIN) = 4
Look for these in your work
- Read inside body
- Correct stop condition
An author writes REPEAT INPUT Mark UNTIL Mark < 0 to ask for a non-negative mark. Explain the defect and correct it.
Give me a hint
UNTIL should describe a valid stopping condition.
Compare my reasoning
- Mark < 0 is invalid input.
- The current loop stops on a negative mark.
- Use Mark >= 0 as the stop condition.
Change the condition to UNTIL Mark >= 0 so the loop ends for an accepted mark.
Look for these in your work
- Defect identified
- Condition corrected
Common mistakes
- Using the condition for continuing instead of stopping
- Forgetting that REPEAT executes before checking
- Writing an invalid condition that accepts values outside the range
What can you explain now?
When is the UNTIL condition checked?
Compare with the explanation
After the loop body
A REPEAT loop is post-condition iteration.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How does the meaning of UNTIL differ from the condition in WHILE?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.