Theory Notes/💻 Topic 1: Solution Development/11.1.3
11.1.3Grade 11

Application Development: Iteration, Arrays & Strings

The workhorses of Paper 1: loops that repeat work, arrays that hold many values, and string handling that appears in almost every practical paper.

LoopUse whenTests
for i := 1 to nYou know how many repetitionsBefore each pass
for i := n downto 1Counting backwardsBefore each pass
while cond doUnknown count; may run zero timesBefore each pass
repeat … until condMust 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.

Strings are 1-based
s[1] is the first character and Length(s) the last — a constant source of off-by-one errors if you're used to 0-based languages.
Copy(s, start, count)
Takes a COUNT, not an end position. Copy('Information', 1, 4) = 'Info'.
Pos(sub, s)
Returns the position of sub in s, or 0 if not found.
Doubling quotes
To put an apostrophe in a literal you double it: 'Can''t'.