Most scenario answers are built from a handful of familiar code patterns, joined together. Learn six of them here — then a 15-mark answer becomes putting blocks together, not inventing from scratch.
Most scenario answers are a few familiar patterns joined together. Recognise the patterns and practise their shapes, and the 15-mark question becomes assembly, not invention.
The six patterns in this lab: 1. Validation loop · 2. Totalling · 3. Counting · 4. Highest or lowest + every match · 5. Nested loops for a 2D array · 6. Messages and comments.
"Build from blocks you already trust." The Read Lab drew up the plan. This Build Lab makes the blocks. The Ship Lab joins them into a complete answer.
WHILE, REPEAT and FOR for a taskWHILE or REPEATTotal ← Total + ValueCount ← Count + 1Total ← 0Not enough — an IF only asks again once. If the second value is also wrong, it is used anyway:
INPUT Score
IF Score < 0 OR Score > 100
THEN
INPUT Score
ENDIF
Right — the loop keeps asking until the value is valid:
OUTPUT "Enter a score from 0 to 100: "
INPUT Score
WHILE Score < 0 OR Score > 100 DO
OUTPUT "Score must be 0 to 100. Try again: "
INPUT Score
ENDWHILE
Also right — REPEAT … UNTIL (the body always runs at least once):
REPEAT
OUTPUT "Enter a score from 0 to 100: "
INPUT Score
UNTIL Score >= 0 AND Score <= 100
Total ← 0
FOR Index ← 1 TO ArraySize
Total ← Total + Numbers[Index]
NEXT Index
OUTPUT "The total is ", Total
Count ← 0
FOR Index ← 1 TO ArraySize
IF Numbers[Index] > Threshold
THEN
Count ← Count + 1
ENDIF
NEXT Index
OUTPUT "Number above the threshold: ", Count
// first pass: find the highest value
Max ← Values[1]
FOR Index ← 2 TO ArraySize
IF Values[Index] > Max
THEN
Max ← Values[Index]
ENDIF
NEXT Index
// second pass: output every name with that value
FOR Index ← 1 TO ArraySize
IF Values[Index] = Max
THEN
OUTPUT "Highest: ", Names[Index]
ENDIF
NEXT Index
Why two passes? You only know the highest value once you have checked every item. The second pass outputs every item that matches it, so ties are not missed. For the lowest, swap > for <.
FOR Row ← 1 TO NumRows
RowTotal ← 0
FOR Col ← 1 TO NumCols
RowTotal ← RowTotal + Grid[Row, Col]
NEXT Col
OUTPUT "Row ", Row, " total: ", RowTotal
NEXT Row
The outer loop goes through the rows (for example, each student) and the inner loop goes through the columns (each day). RowTotal ← 0 sits inside the outer loop, so each row starts again from 0.
Put a message before every INPUT so the user knows what to type, and a label with every OUTPUT so the user knows what it shows. Add a // comment to each part of the program explaining its purpose — what that part is for, not a word-for-word description of the code.
ARRAY[1:ArraySize]. If a scenario declares an array from 0, the loop runs from 0 to ArraySize − 1 instead.Total ← 0 before the loop; add each score inside it.CountAbove ← 0 before the loop; add 1 inside it when the score is over 80.FOR loop. After the loop, Average ← Total / ArraySize, then output both with messages.WeeklyTotal[].Min ← WeeklyTotal[1], then check from index 2, updating Min when a total is smaller.WeeklyTotal equals Min.An IF only asks again once. If the second value is also wrong, it is used anyway.
Without Total ← 0 before the loop, Total ← Total + … has nothing to add to.
"Output the name(s) of the student(s) with the lowest total" — outputting only the first one found misses any ties.
If every value is negative, Max ← 0 never changes. If every value is positive, Min ← 0 never changes.
Max ← Values[1]), then check from index 2.// add 1 to Count tells the reader nothing new. // count the days with more than 300 minutes explains the purpose.
In our own words — the kinds of thing the mark scheme looks for.
Total ← 0, before the loop starts.Min ← Values[1] — then check from index 2.RowTotal ← 0 go in a nested loop?// count students over the limit, not // add 1 to Count.ARRAY[1:30]. What should the FOR loop be?FOR Index ← 1 TO 30. Starting at 0 would use an index that doesn't exist.Head to Activities for the Pattern Builder. Fill in the gaps; your code is run on test data to check it works.
11.1–11.2 Read Lab
📍 11.3 Build Lab (this page)
11.4 Ship Lab
Topic 11 is this site's practice for the 15-mark scenario question at the end of Paper 2. These patterns come from syllabus Topic 7 (validation, totalling, counting, finding highest and lowest) and Topic 8 (iteration, selection, arrays).
Getting started. Why do experienced programmers write code quickly? Not because they type faster — because they recognise patterns they have written many times before.
Context. A simple calculator program inputs two numbers and an operator, checks the operator, works out the answer and outputs it. Underneath, it is just a few patterns: inputs with messages, a validation loop, selection, and an output with a label.
Discussion. Why is IF Score < 0 THEN INPUT Score ENDIF not enough? What happens if the second value is also wrong?
INPUT Score
IF Score < 0 OR Score > 100
THEN
INPUT Score
ENDIF
A second wrong value gets through.
INPUT Score
WHILE Score < 0 OR Score > 100 DO
OUTPUT "Try again: "
INPUT Score
ENDWHILE
Only a valid value gets past the loop.
Use when: the loop may not need to run at all.
Good fit: validation after a first input; reading until a rogue value.
Use when: the body must run at least once.
Good fit: menus; "keep asking until…".
Use when: you know how many times to repeat.
Good fit: going through an array; totalling; counting.
A warm-up for the Pattern Builder. Tap the pattern you would use.
| Structure | Pseudocode | Use it for |
|---|---|---|
| Pre-condition loop | WHILE … DO … ENDWHILE | Repeat while a condition is true; may not run at all |
| Post-condition loop | REPEAT … UNTIL … | Repeat until a condition is true; always runs once |
| Count-controlled loop | FOR Index ← 1 TO N … NEXT Index | A known number of repeats |
| Count with a step | FOR Index ← 1 TO N STEP 2 … NEXT Index | Counting up in a different step |
| Selection | IF … THEN … ELSE … ENDIF | Two-way choice (IFs can be nested inside each other) |
| Case selection | CASE OF Choice … OTHERWISE … ENDCASE | Many choices on one value, e.g. a menu |
An IF only asks again once.
Forgetting Count ← 0 before the loop.
Fails when every value is negative (Max) or every value is positive (Min). Start from the first element.
An array declared ARRAY[1:N] needs FOR Index ← 1 TO N. Starting at 0 uses an element that doesn't exist.
RowTotal ← 0 must go inside the outer loop. Put it before both loops and every row adds on to the last one.
// add 1 to Count says nothing new. Explain the purpose.
IF Score < 0 THEN INPUT Score ENDIF — enough validation?Six patterns, when to use each, and the traps to avoid.
Head to Activities — the Pattern Builder and four short drills.
In the Pattern Builder you fill the gaps in each pattern. Your finished code is run on test data, so any correct version works — not just one exact answer. Use the variable names given in the brief.
Unlocking: Patterns 1–3 are open. Patterns 4 and 5 unlock after you complete 2 of Patterns 1–3. Pattern 6 unlocks after you complete any 3.
Type ← as <- if your keyboard doesn't have an arrow.
Which loop fits the task: WHILE, REPEAT or FOR?
Read the code. Is the starting value set correctly, in the right place?
Does the requirement need one output, or a second pass to output every match?
Quick recall on the six patterns. Sprint is for speed — it doesn't change your Mastery.
✅ = completed · 🔒 = locked
1 · Pattern Builder — fill the gaps; your code runs on test data.
2 · Loop Choice — WHILE, REPEAT or FOR.
3 · Initialisation Detective — spot a missing or misplaced starting value.
4 · Every Match? — one output, or every match.
5 · Sprint — 60 seconds of quick recall.
Across the six patterns and choosing patterns. Skills you get wrong come back more often. Missed questions are saved to Mistakes.
Paper 2 style questions on the six patterns. Write your pseudocode, then press Mark my answer. Code answers are run on test data, so any correct version earns the marks.
Written in the style of Cambridge Paper 2; the scenarios are made up for practice. Use the variable names in the question. Both ← and <- work, and MOD, DIV, LENGTH and CASE are understood.
Read these before your exam. Then look at Mistakes to see the ones you make.
Six one-liners to recite before your exam.
Tick each item as you master it. In the skill grid, tap a status chip to set it yourself. When all 12 are ticked, the Module Mastered banner appears.
Mastered = 3+ attempts and at least 70% accuracy. Tap the status chip to override it.
Join the patterns into complete answers to full scenarios, and check them against what a good answer shows.
11.1–11.2 Read Lab
📍 11.3 Build Lab (this page)
11.4 Ship Lab
Every wrong Practice, Exam or Pattern Builder answer is saved here automatically.
Your attempts, accuracy and mastery counts in the Build Lab.
Bookmark an exam question to save it here.
Jot notes as you learn. Everything here is saved on this device only.
Sent mistakes and saved key facts, in one place.