Grade 10 · Practical
Iteration (loops)
Introduction to Programming (Delphi) · about 4 min
Iteration repeats a block of code. Choose the loop that matches whether you know the number of repetitions in advance.
Key points- `for i := 1 to n do` — a KNOWN, fixed number of repetitions (a counter loop).
- `while condition do` — repeat while a condition holds; tests BEFORE each pass (may run zero times).
- `repeat … until condition` — tests AFTER each pass, so it always runs at least once.
- Guard against infinite loops: something inside a while/repeat must eventually make the condition stop.
- Loop / iteration — repeating a block of statements.
- Counter — a variable that counts the passes of a loop.
- Infinite loop — a loop whose stop condition is never met.
EXAM TIP
"read values until the user enters 0" is a WHILE (unknown count); "do this for each of the 12 months" is a FOR (known count).