FL
🔨 Topic 11 Programming scenarios · 11.3

11.3 Build Lab

Every 15-mark Paper 2 Q11 solution is 3-5 patterns wired together. Six patterns cover the lot. Master them here and the exam becomes assembly, not invention.

💡 Lab A recommended but not required. Lab A drills scenario reading; Lab B drills the code patterns. If you skipped Lab A that's fine — come back to it if pattern practice reveals reading gaps. Lab A · Read
🧪 Exam Mode ON — recall from memory, then reveal
§1 · Topic Overview

Why patterns?

Every Paper 2 Q11 solution is 3-5 patterns wired together. Recognise the patterns, memorise the shapes, and the 15-mark question becomes assembly, not invention. Six patterns cover every scenario Cambridge has set since 2023.

The six patterns Lab B teaches: 1. Validated input loop · 2. SUM aggregation · 3. COUNT with condition · 4. MIN/MAX + find all matches · 5. Nested loop for 2D array · 6. Comments + messages.

🔨 The Forge metaphor

"Assemble reusable technique blocks." Lab A read the blueprint. Lab B forges the blocks. Lab C ships the finished 15-mark program.

§2 · Learning Objectives

By the end of Lab B you will be able to:

  • Write a validated input loop that retries until valid (not just once)
  • Choose WHILE vs REPEAT vs FOR for a given task
  • Write SUM aggregation for a 1D array with correct initialisation
  • Write COUNT-if with a threshold condition
  • Write MIN / MAX search + second pass to output ALL matches
  • Write nested loops for 2D array traversal with the correct outer/inner order
  • Add appropriate comments (WHY, not WHAT) and messages (all I/O)
  • Recognise which pattern a scenario requirement needs
  • Combine 2-3 patterns into a working sub-solution
§3 · Key Terminology

Nine terms that assemble the pattern vocabulary

Pattern — a reusable block of code that solves a recurring sub-problem (validate an integer, sum an array, find a max)
Validated input loop — INPUT + condition + retry, using WHILE, REPEAT, or FOR-with-flag. Never a bare IF.
Aggregation — reducing many values to one (SUM · COUNT · AVERAGE · MIN · MAX)
Nested loop — a loop inside a loop. Cambridge 2D array traversal always uses this.
Running total — a variable that accumulates as the loop iterates. Requires initialisation to zero before the loop.
Counter — a variable that increments when a condition matches inside a loop. Initialise to zero.
Initialisation — setting a variable to its starting value before the loop reads or updates it. Missing this is a Cambridge examiner-cited trap.
Sentinel value — a special input value that ends the loop (e.g. -1, "END", "STOP")
Off-by-one error — looping one iteration too few or too many. Cambridge arrays are 1-indexed.
§4 · Core Theory · the six patterns

§4.1 · Pattern 1 — Validated input loop (the CRITICAL one)

Wrong (Cambridge examiner-cited failure mode from 2025 s25 P22 Q11 — verbatim: "Some candidates used an IF statement to validate the entry, but this only allows for one extra data entry"):

INPUT Score
IF Score < 0 OR Score > 100 THEN
   INPUT Score
ENDIF

Right — retries until valid, full marks:

INPUT Score
WHILE Score < 0 OR Score > 100 DO
   OUTPUT "Score must be 0 to 100. Try again: "
   INPUT Score
ENDWHILE

Alternative valid (REPEAT-UNTIL):

REPEAT
   INPUT Score
UNTIL Score >= 0 AND Score <= 100

§4.2 · Pattern 2 — SUM aggregation

Total <- 0
FOR i <- 1 TO ArraySize
   Total <- Total + Numbers[i]
NEXT i
OUTPUT "The total is ", Total

§4.3 · Pattern 3 — COUNT with condition

Count <- 0
FOR i <- 1 TO ArraySize
   IF Numbers[i] > Threshold THEN
      Count <- Count + 1
   ENDIF
NEXT i
OUTPUT "Count above threshold: ", Count

§4.4 · Pattern 4 — MIN / MAX + find all matches

Max <- Values[1]
FOR i <- 2 TO ArraySize
   IF Values[i] > Max THEN
      Max <- Values[i]
   ENDIF
NEXT i

// second pass to output ALL indices with the max value
FOR i <- 1 TO ArraySize
   IF Values[i] = Max THEN
      OUTPUT Names[i]
   ENDIF
NEXT i

Why two passes: 2025 s25 examiner report flags outputting ONE match when multiple exist. Second pass fixes it.

§4.5 · Pattern 5 — Nested loop for 2D array

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

§4.6 · Pattern 6 — Comments + messages

Every INPUT gets a prompt message. Every OUTPUT gets a label string. Every logical block gets a // comment explaining its purpose (not what — the code shows what). Cambridge mark scheme axes 4-5 literally reward these.

§5 · Worked Examples

WE1 · Validated integer input 0-100 · three legal flavours

Flavour A · WHILE (pre-check): input first, then loop while invalid.
Flavour B · REPEAT (post-check): loop the input, exit when valid. Always runs at least once.
Flavour C · FOR-with-flag: a FOR loop with a boolean flag Valid <- FALSE, exit when set TRUE. Verbose but Cambridge accepts.
Which does Cambridge prefer? All three earn full marks. WHILE is most common in mark schemes; use whichever you write fastest and cleanest.

WE2 · Average + Count-above-threshold · two patterns wired

Pattern 2 (SUM): initialise Total to 0, loop, accumulate.
Pattern 3 (COUNT): initialise CountAbove to 0, loop, increment when Score > 80.
Wire: both patterns share the same FOR loop over the array. One pass, two accumulators. Output both after the loop.

WE3 · Lowest weekly total from 2D array · MIN + nested + all matches

Pattern 5 (Nested): outer FOR over students, inner FOR over weekdays, accumulate WeeklyTotal per student into a 1D array.
Pattern 4 (MIN): initialise Min to WeeklyTotal[1], loop 2 to ClassSize, update if smaller.
All matches (Pattern 4 second pass): second FOR loop to output every student whose WeeklyTotal equals Min. Models 2024 s24 P22 Q11 verbatim.
§6 · Common Misconceptions

Five anchor traps (Review tab has all 10)

Trap · Using IF for validation instead of a loop

Bare IF allows exactly ONE retry. If the second input is also invalid, it's stored anyway. Marks lost.

Fix: WHILE or REPEAT. Always. Cited: 2025 s25 P22 Q11 examiner report — "only allows for one extra data entry".

Trap · Not initialising counters or totals to zero

Forgetting Total <- 0 before the SUM loop means the first iteration adds to undefined. Cambridge flags this.

Fix: initialise every accumulator on the line before the loop. Cited: 2023 F/M P22 Q11 examiner report — "not initialising counters to zero".

Trap · Outputting one match when all matches are required

"Output the student with the lowest total" — you output one name and stop. But multiple students can tie. Second pass fixes it.

Fix: MIN/MAX pass finds the value; second pass outputs every index whose value equals it. Cited: 2025 s25 P22 Q11 verbatim.

Trap · Initialising MIN/MAX to 0

If all your values are positive, MIN never updates below 0. If all negative, MAX never updates above 0. Both fail silently.

Fix: initialise to the first array element (Min <- Values[1]), then loop 2 to ArraySize.

Trap · Omitting comments explaining WHY

Cambridge doesn't want comments like // increment counter — the code already shows that. It wants // count students with screen time over 300 minutes.

Fix: comments explain purpose or function, not action. Cited: mark scheme axis 5 — verbatim.
§7 · Cambridge Exam Focus

Mark-scheme phrases to recognise

"more than one technique seen applied to the scenario" — the techniques axis rewards multiple patterns wired together
"appropriate messages to accompany all inputs and outputs" — messages on every I/O, not just some
"comments to explain the purpose or function of each part" — purpose comments, not action commentary
"data structures used correctly in the way expected" — Cambridge names must be preserved and indexed properly
"validation using an iteration structure" — the loop pattern, not IF
§8 · Quick Knowledge Check

Tap each card to reveal (0/8 revealed)

Q1 · Is IF Score < 0 OR Score > 100 THEN INPUT Score ENDIF valid validation?
✅ No. IF allows only ONE retry. Cambridge requires a loop (WHILE / REPEAT / FOR-with-flag). This is the 2025 s25 P22 Q11 examiner-cited failure mode.
Q2 · You want to SUM an array. What value do you initialise the accumulator to?
✅ Zero. Total <- 0 on the line before the loop. Miss this and you lose the "not initialising counters" axis.
Q3 · You want to find MIN. What do you initialise Min to?
✅ The first array element: Min <- Values[1], then loop from index 2. Initialising to 0 fails when all values are positive.
Q4 · When Cambridge asks "output the students with the lowest total", how many statements do you need?
✅ Two loops. One to find MIN, one to output every match. Second pass is the Trap-3 fix.
Q5 · For 2D array traversal — outer loop iterates rows or columns first?
✅ Rows outer, columns inner. Cambridge convention. Swap them and you get column-major traversal, which is legal but non-standard and rare in mark schemes.
Q6 · WHILE vs REPEAT — which one always runs the body at least once?
✅ REPEAT (post-check). WHILE (pre-check) may skip the body entirely if the condition is already false.
Q7 · What's the difference between a good comment and a bad one?
✅ A good comment explains WHY (purpose or function). A bad one explains WHAT (the code already shows that). // increment counter is bad; // count matches above the threshold is good.
Q8 · Cambridge Pseudocode arrays start at what index?
✅ 1. Not 0. FOR i <- 0 TO N is off by one at both ends and loses marks.
§9 · Ready for Activities?

🎯 You've got the patterns. Head to Activities to wire them together in Pattern Builder.

Six patterns · 4 slots each · parser marks your fill against the reference AST.

🔨 The six patterns

  1. Validated input loop
  2. SUM aggregation
  3. COUNT with condition
  4. MIN/MAX + all matches
  5. Nested loop for 2D
  6. Comments + messages

📊 Progress

0Practice attempted
0Exam attempted
0Skills mastered

🎯 Weakest skills

§1 · Textbook card

Getting Started · Context · Discussion

Getting Started. Why do experienced programmers write faster? Not because they type faster — because they recognise patterns. The same 5 patterns appear on every Paper 2 Q11.

Context. Textbook §11.3 walks through a calculator example: input two values, input an operator, perform the calculation, output the result. Underneath: two INPUT + validate patterns, one selection pattern, one OUTPUT with message. Nothing new — just four patterns wired together.

Discussion. Why is IF Score < 0 THEN INPUT Score broken? What happens if the second input is also invalid?

Tap to reveal
✅ The second (invalid) input is stored. Cambridge's mark scheme literally cites this in 2025 s25 P22 Q11: "only allows for one extra data entry". The fix is a loop that retries until valid — not a single retry.
§2 · Contrast box · IF-validation vs loop-validation

IF-validation (WRONG)

INPUT Score
IF Score < 0 OR Score > 100 THEN
   INPUT Score
ENDIF

Impact: one retry only. If second is bad, it's stored. Cited: 2025 s25 P22 Q11 examiner report.

Loop-validation (RIGHT)

INPUT Score
WHILE Score < 0 OR Score > 100 DO
   OUTPUT "Try again: "
   INPUT Score
ENDWHILE

Impact: retries until valid. Full marks on the validation axis.

§3 · Contrast box · WHILE vs REPEAT vs FOR

WHILE (pre-check)

When: condition may not hold at all — body may not execute.
Cambridge preference: validation loops, sentinel-terminated inputs.

REPEAT (post-check)

When: body must execute at least once.
Cambridge preference: menu-driven programs, "keep asking until…" flows.

FOR (count-controlled)

When: known iteration count (array length, week count).
Cambridge preference: array traversal, aggregation.

§4 · Secondary interactive · Pattern Match Quiz

Given a requirement — which pattern applies?

Warm-up before Pattern Builder. Tap the pattern you'd use, get instant feedback.

§5 · Cambridge syntax reference · 6 loop and selection structures
StructurePseudocodeWhen to use
Pre-check loopWHILE cond DO … ENDWHILECondition may not hold — body may not run
Post-check loopREPEAT … UNTIL condBody always runs at least once
Count-controlledFOR i <- 1 TO N … NEXT iKnown iteration count
Count + stepFOR i <- 1 TO N STEP 2 … NEXT iNon-1 increment
SelectionIF cond THEN … ELSE … ENDIFTwo-way branch
Nested selectionIF … ELSE IF … ELSE … ENDIFMulti-way branch
§6 · Inline trap cards

6 examiner-cited traps to internalise here (Review has all 10)

Trap 1 · IF for validation instead of loop

Recurring across all sittings. The 2025 s25 P22 Q11 examiner report says it verbatim.

Source: 2025 s25 P22 Q11 examiner report — verbatim

Trap 2 · Not initialising counters to zero

Forgetting Count <- 0 before the loop. Counter accumulates from undefined.

Source: 2023 F/M P22 Q11 examiner report — verbatim

Trap 3 · Initialising MIN/MAX to zero

Fails silently for arrays where all values sit above or below zero. Initialise to the first element instead.

Source: textbook §11.3 general habit

Trap 4 · Off-by-one in FOR bounds

FOR i <- 0 TO N in Cambridge Pseudocode is off by one at both ends. Arrays start at 1.

Source: 0478 syllabus convention

Trap 5 · Nested loops in wrong outer/inner order

Iterating columns outer and rows inner is legal but non-standard. Cambridge convention is rows outer.

Source: 2024 s24 P22 Q11 mark scheme

Trap 6 · Comments explaining WHAT not WHY

// increment counter is worthless — the code shows that. // count students over 300 minutes explains purpose.

Source: mark scheme axis 5 — "explain the purpose or function"
§7 · Quick predict-then-reveal (4 items)
Q1 · Given IF Score < 0 THEN INPUT Score ENDIF, is this correct validation?
✅ No. IF only allows one retry. Cambridge requires a loop that retries until valid.
Q2 · You're finding the lowest score. Do you initialise Min to 0 or to Values[1]?
✅ Values[1]. Initialising to 0 breaks if all values are positive.
Q3 · For 2D traversal, outer loop is rows or columns?
✅ Rows outer. Cambridge convention.
Q4 · "Output the winners" — is one OUTPUT statement enough?
✅ No. Loop and output all matches. 2025 s25 P22 Q11 verbatim examiner-cited trap.

💡 Learn tab in one line

Six patterns. Cambridge preference for each. Traps to avoid.

🎓 What next

Head to Activities — Pattern Builder + 4 partner drills.

🔨 Pattern Builder + 4 partner drills

Five drills. The signature is Pattern Builder — 6 pattern skeletons with editable slots. The pseudocode parser marks your fill against the reference AST. Behind it: 4 partner drills that isolate sub-skills — loop-choice reflex, initialisation habit, all-matches reflex, and 60-second sprint.

Progressive disclosure: Modes 1-3 open. Modes 4-5 unlock after 2 of 1-3 completed. Mode 6 unlocks after 3 of 1-5.

1 · 🔨 Pattern Builder (signature)

Select a pattern above to start.

2 · 🔁 Loop-Choice Reflex

Given a task, pick the correct loop: WHILE / REPEAT / FOR. Instant feedback with Cambridge reasoning.

3 · 🕵️ Init Detective

Read a code snippet. Tap YES if the initialisation is correct, NO if it will break. Wrong ones flag the trap.

4 · 🎯 All-Matches Reflex

Given a Cambridge output requirement, tap one-pass or two-pass. Second-pass is required whenever the answer could tie.

5 · ⚡ 60-second Sprint

Rapid recall on all six patterns. Pattern-picking + loop-choice + init-check questions.

60Seconds
0Correct
0Streak

📇 Pattern deck

6 patterns · progressive unlock

🎯 Skill coverage

💡 Drill guide

1 · Pattern Builder — signature. Fill slot expressions, parser AST-marks your fill.

2 · Loop-Choice — isolate the WHILE/REPEAT/FOR reflex.

3 · Init Detective — spot bad initialisation before it costs marks.

4 · All-Matches — reflex the second-pass on ties.

5 · Sprint — 60s rapid recall.

✎ Practice — 18 adaptive MCQs

Distributed across the 6 patterns and pattern-picking. Adaptive: weak skills surface 2× more often.

🧪 Practice Exam Mode ON. Recall the answer, then reveal + self-mark.

📊 Practice stats

0Attempts
Accuracy

🎯 Weakest skills

📋 Exam pool — 12 Paper 2 cited items

Real Cambridge Paper 2 Q11 scenarios from 2023-2025, plus textbook cases. Every citation verified. Answer, then reveal the mark scheme.

📋 Exam stats

0Attempts
Average

🔄 Review — 10 traps + 6 memory triggers

The traps here are the ones examiner reports flag repeatedly across 2023-2025. Read this tab the morning of the exam.

Examiner-cited & source-cited traps

🧠 Memory triggers

Six one-liners. Recite these before your exam.

🎯 Your weakest skills

💔 Your logged mistakes

🏆 Mastery — 12-item revision checklist

Tick each item as you internalise it. Tap a skill status to override the automatic marker. When all 12 are ticked, the Module Mastered banner appears.

🏆 Module Mastered · Lab B · Build complete. Move on to Lab C.

Revision checklist

Skill-by-skill mastery

📊 Overview

0Skills attempted
0Skills mastered

Next step

Once all 12 checked → Lab C · Ship (Deliverable). Full 15-mark end-to-end programs.

💔 Mistakes

Your mistakes log

Every wrong answer captures here automatically.

📊 Progress

Progress dashboard

Your attempts, accuracy, and mastery counts across Lab B.

Practice

0Attempts
Accuracy

Exam

0Attempts
Average

Focus recommendation

Weakest skills

🔖 Bookmarks

Bookmarked questions

📝 My Notes

Personal notes + feedback

Add a note

Report feedback

Spotted something wrong or unclear? Log it here.

Quick stats

0Notes saved
0Feedback items
🗄️ Vault

Your knowledge vault

Saved ✓