Pseudocode
A WHILE loop is condition-controlled: it repeats a block of statements while a condition is true. The condition is checked at the start of every iteration. If it is false the first time, the body never runs.
people_waiting = int(input("How many are waiting? "))
while people_waiting > 0:
print("Serving a customer")
people_waiting = people_waiting - 1
print("Queue empty")Output when the user types 0:
How many are waiting? 0
Queue empty
Here, the loop serves customers only while the number waiting is above zero. Enter 0 and the body is skipped completely, so a WHILE loop can run zero times.
A REPEAT UNTIL loop is another condition-controlled loop, but the condition is tested after the body. The body always runs at least once. It continues until the condition becomes true, which means it loops while the condition is false. This suits a task where you must do something once before you can decide whether to stop, such as asking for a value and checking it afterwards.
| Feature | WHILE | REPEAT UNTIL |
|---|---|---|
| Where the condition is tested | At the start | After the body |
| Fewest runs of the body | 0 | 1 |
| Repeats while | The condition is true | The condition is false |
| Stops when | The condition is false | The condition is true |
Edexcel GCSE Computer Science · Pseudocode
Edexcel GCSE Computer Science · Variables & Constants
Edexcel GCSE Computer Science · Condition Controlled Iteration (While Loops)