The workhorses of Paper 1: loops that repeat work, arrays that hold many values, and string handling that appears in almost every practical paper.
| Loop | Use when | Tests |
|---|---|---|
| for i := 1 to n | You know how many repetitions | Before each pass |
| for i := n downto 1 | Counting backwards | Before each pass |
| while cond do | Unknown count; may run zero times | Before each pass |
| repeat … until cond | Must run at least once (menus, validation) | After each pass |
💡 Exam Tip
repeat…until stops when the condition becomes TRUE; while continues while it is true. They are opposites, and swapping them produces an infinite loop.
Static arrays declare their own index range, so `array[1..30]` genuinely starts at 1 — unlike Java. Dynamic arrays use `array of` with SetLength and always start at 0; High() gives the last valid index and Length() the count.
Example
var marks: array[1..5] of Integer; names: array of String; i, total: Integer; begin total := 0; for i := 1 to 5 do total := total + marks[i]; WriteLn('Average: ', (total / 5):0:2); SetLength(names, 3); // indices 0, 1, 2 for i := 0 to High(names) do WriteLn(names[i]); end.