A counted loop repeats a predetermined number of times, whereas a conditional loop repeats according to whether a Boolean condition is true or false. Counted loops are normally implemented using FOR; conditional loops commonly use WHILE or REPEAT...UNTIL.
How the Loops Work
A counted loop uses a loop control variable that changes systematically. Its initial value, final value, and increment determine the number of iterations.
FOR index FROM 1 TO 5
OUTPUT index
END FOR
This loop executes exactly five times because the range is known before execution.
A conditional loop evaluates a Boolean expression to decide whether repetition should continue. The number of iterations may not be known in advance.
WHILE password is incorrect
INPUT password
END WHILE
The loop ends only when the password is correct. The program must update information affecting the condition; otherwise, an infinite loop may occur.
| Feature | Counted loop | Conditional loop |
|---|---|---|
| Main construct | FOR | WHILE or REPEAT...UNTIL |
| Termination | Control variable reaches its final value | Boolean condition changes state |
| Iterations known beforehand | Usually yes | Usually no |
| Typical use | Processing every element in a fixed range | Repeating input until it is valid |
| Possible zero executions | Depends on the language and range | WHILE may execute zero times |
A WHILE loop is a pre-condition loop because it tests its condition before executing the body. A REPEAT...UNTIL loop is a post-condition loop because it tests after the body, so the body executes at least once.
A common misconception is that every loop with a variable is a counted loop. A conditional loop may also update a counter, but it remains conditional if a Boolean condition directly controls termination.
IB Exam Technique
For B2.3 Programming constructs, identify what controls termination. When asked to distinguish the loops, state both the iteration mechanism and whether the number of repetitions is known in advance. In trace questions, update the control variable or condition after every iteration and check exactly when the termination test occurs.