FL
🔨 Topic 11 Programming scenarios · Page 11.3

11.3 Build Lab

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.

💡 The Read Lab comes first, but it isn't required. It practises reading a scenario; this lab practises the code. If pattern practice shows gaps in your reading, go back to the Read Lab.
🧪 Exam Mode ON — recall from memory, then reveal
§1 · Topic Overview

Why patterns?

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.

🔨 The workshop idea

"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.

§2 · Learning Objectives

By the end of this lab you will be able to:

  • Write a validation loop that keeps asking until the input is valid
  • Choose between WHILE, REPEAT and FOR for a task
  • Total the values in an array, starting the total at 0
  • Count the values that meet a condition
  • Find the highest or lowest value, then output every item that matches it
  • Use nested loops to go through a 2D array
  • Add messages to inputs and outputs, and comments that explain each part
  • Say which patterns a requirement needs, and join two or three of them together
§3 · Key Terminology

Nine terms for building with patterns

Pattern — a reusable block of code for a common job: check an input, total an array, find the highest value
Validation loop — an input plus a condition that keeps asking until the value is valid, using WHILE or REPEAT
Totalling — adding values into a running total: Total ← Total + Value
Counting — adding 1 when a condition is met: Count ← Count + 1
Initialisation — giving a variable its starting value before the loop uses it, e.g. Total ← 0
Nested loop — a loop inside a loop; the usual way to go through every element of a 2D array
Second pass — going through the data again to output every item that matches a value found in the first pass
Rogue value — a special input such as -1 that tells the program to stop reading values
Off-by-one error — a loop that runs one time too many or too few, often from wrong array bounds
§4 · Core Theory · the six patterns

§4.1 · Pattern 1 — Validation loop

Not 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

§4.2 · Pattern 2 — Totalling

Total ← 0
FOR Index ← 1 TO ArraySize
   Total ← Total + Numbers[Index]
NEXT Index
OUTPUT "The total is ", Total

§4.3 · Pattern 3 — Counting

Count ← 0
FOR Index ← 1 TO ArraySize
   IF Numbers[Index] > Threshold
      THEN
         Count ← Count + 1
   ENDIF
NEXT Index
OUTPUT "Number above the threshold: ", Count

§4.4 · Pattern 4 — Highest + every match

// 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 <.

§4.5 · Pattern 5 — Nested loops for a 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

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.

§4.6 · Pattern 6 — Messages and comments

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.

📎 Useful background — arrays and bounds

Arrays use the bounds they are declared with. These examples assume arrays declared from 1, e.g. ARRAY[1:ArraySize]. If a scenario declares an array from 0, the loop runs from 0 to ArraySize − 1 instead.
§5 · Worked Examples

WE1 · Validated score · two correct ways

WHILE (check first): input once, then loop while the value is invalid, asking again inside the loop.
REPEAT (check last): put the input inside the loop and repeat until the value is valid. It always runs at least once.
Which is better? Both work. Use whichever you can write clearly and correctly.

WE2 · Average and count above 80 · two patterns in one loop

Totalling: Total ← 0 before the loop; add each score inside it.
Counting: CountAbove ← 0 before the loop; add 1 inside it when the score is over 80.
Join them: both updates sit in the same FOR loop. After the loop, Average ← Total / ArraySize, then output both with messages.

WE3 · Lowest weekly total · nested loops + lowest + every match

Nested loops: the outer loop goes through the students, the inner loop through the 7 days; store each student's total in WeeklyTotal[].
Lowest: Min ← WeeklyTotal[1], then check from index 2, updating Min when a total is smaller.
Every match: a second loop outputs every student whose WeeklyTotal equals Min.
§6 · Common Misconceptions

Five key traps (Review has all 10)

Trap · Using IF to validate

An IF only asks again once. If the second value is also wrong, it is used anyway.

Fix: use WHILE or REPEAT so the program keeps asking. A Cambridge examiner report (2025) noted that an IF only allows one extra data entry.

Trap · Not initialising totals and counters

Without Total ← 0 before the loop, Total ← Total + … has nothing to add to.

Fix: set every total and counter to 0 before the loop starts.

Trap · Outputting one match when several tie

"Output the name(s) of the student(s) with the lowest total" — outputting only the first one found misses any ties.

Fix: find the value first, then a second pass outputs every item that matches it.

Trap · Starting Max or Min at 0

If every value is negative, Max ← 0 never changes. If every value is positive, Min ← 0 never changes.

Fix: start from the first element (Max ← Values[1]), then check from index 2.

Trap · Comments that repeat the code

// add 1 to Count tells the reader nothing new. // count the days with more than 300 minutes explains the purpose.

Fix: write each comment about what that part of the program is for.
§7 · Exam Focus

What a good answer shows

In our own words — the kinds of thing the mark scheme looks for.

Several techniques used for the scenario — selection, iteration, counting, totalling, input and output
Inputs validated with a loop that keeps asking until the value is valid
Suitable messages with inputs and outputs
Comments explaining the purpose of each part
The data structures from the scenario used with the names given
§8 · Quick Knowledge Check

Tap each card to reveal (0/8 revealed)

Q1 · Is an IF enough to validate an input?
✅ No — it only asks again once. Use a WHILE or REPEAT loop that keeps asking until the value is valid.
Q2 · What do you set a total to before the loop?
✅ 0 — Total ← 0, before the loop starts.
Q3 · What do you set Min to before finding the lowest value?
✅ The first element — Min ← Values[1] — then check from index 2.
Q4 · "Output the name(s) of the student(s) with the lowest total." How many loops after the totals are worked out?
✅ Two: one to find the lowest total, one to output every student with that total.
Q5 · Where does RowTotal ← 0 go in a nested loop?
✅ Inside the outer loop, just before the inner loop — so each row starts again from 0.
Q6 · WHILE or REPEAT — which always runs its body at least once?
✅ REPEAT — the condition is checked at the end. WHILE checks first, so its body may not run at all.
Q7 · What makes a good comment?
✅ It explains the purpose of that part: // count students over the limit, not // add 1 to Count.
Q8 · An array is declared 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.
§9 · Ready for Activities?

🎯 You know the patterns. Now build them.

Head to Activities for the Pattern Builder. Fill in the gaps; your code is run on test data to check it works.

🔨 The six patterns

  1. Validation loop
  2. Totalling
  3. Counting
  4. Highest or lowest + every match
  5. Nested loops for 2D
  6. Messages and comments

📊 Where you are

0Practice attempts
0Exam questions
0Skills mastered

🎯 Weakest skills

Topic 11 Path

11.1–11.2 Read Lab
📍 11.3 Build Lab (this page)
11.4 Ship Lab

Cambridge syllabus

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).

§1 · Getting started

Getting started · Context · Discussion

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?

Tap to reveal
✅ The second value is used even if it is still wrong — the IF only asks again once. A loop keeps asking until the value is valid.
§2 · Contrast box · IF vs a loop

❌ IF (asks again once)

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

A second wrong value gets through.

✅ WHILE (keeps asking)

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

Only a valid value gets past the loop.

§3 · Choosing a loop

WHILE (check first)

Use when: the loop may not need to run at all.
Good fit: validation after a first input; reading until a rogue value.

REPEAT (check last)

Use when: the body must run at least once.
Good fit: menus; "keep asking until…".

FOR (count-controlled)

Use when: you know how many times to repeat.
Good fit: going through an array; totalling; counting.

§4 · Pattern Match Quiz

Which pattern does this requirement need?

A warm-up for the Pattern Builder. Tap the pattern you would use.

§5 · Pseudocode reference

Loops and selection

StructurePseudocodeUse it for
Pre-condition loopWHILE … DO … ENDWHILERepeat while a condition is true; may not run at all
Post-condition loopREPEAT … UNTIL …Repeat until a condition is true; always runs once
Count-controlled loopFOR Index ← 1 TO N … NEXT IndexA known number of repeats
Count with a stepFOR Index ← 1 TO N STEP 2 … NEXT IndexCounting up in a different step
SelectionIF … THEN … ELSE … ENDIFTwo-way choice (IFs can be nested inside each other)
Case selectionCASE OF Choice … OTHERWISE … ENDCASEMany choices on one value, e.g. a menu
§6 · Trap cards

Six traps to know (Review has all 10)

Trap 1 · Using IF to validate

An IF only asks again once.

Cambridge examiner report (2025) — an IF only allows one extra data entry

Trap 2 · Not initialising totals and counters

Forgetting Count ← 0 before the loop.

Cambridge examiner report (2023) — not initialising counters was a common error

Trap 3 · Starting Max or Min at 0

Fails when every value is negative (Max) or every value is positive (Min). Start from the first element.

Good exam habit

Trap 4 · Loop bounds that don't match the array

An array declared ARRAY[1:N] needs FOR Index ← 1 TO N. Starting at 0 uses an element that doesn't exist.

Good exam habit

Trap 5 · Resetting in the wrong place

RowTotal ← 0 must go inside the outer loop. Put it before both loops and every row adds on to the last one.

Good exam habit

Trap 6 · Comments that repeat the code

// add 1 to Count says nothing new. Explain the purpose.

Good exam habit
§7 · Predict, then reveal
Q1 · IF Score < 0 THEN INPUT Score ENDIF — enough validation?
✅ No. It asks again only once. Use a loop.
Q2 · Finding the lowest score: start Min at 0 or at Values[1]?
✅ Values[1]. Starting at 0 fails when every score is above 0.
Q3 · Totals for each student from a 2D array: which loop goes outside?
✅ The loop over the students, so each student's total is finished before moving to the next student.
Q4 · "Output the winner(s)." Is one OUTPUT after the search enough?
✅ No. Find the winning score, then loop again and output every name that matches it.

💡 Learn tab in one line

Six patterns, when to use each, and the traps to avoid.

🎓 What next

Head to Activities — the Pattern Builder and four short drills.

🔨 Pattern Builder + 4 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.

1 · 🔨 Pattern Builder

Choose a pattern above to start.

Type ← as <- if your keyboard doesn't have an arrow.

2 · 🔁 Loop Choice

Which loop fits the task: WHILE, REPEAT or FOR?

3 · 🕵️ Initialisation Detective

Read the code. Is the starting value set correctly, in the right place?

4 · 🎯 Every Match?

Does the requirement need one output, or a second pass to output every match?

5 · ⚡ 60-second Sprint

Quick recall on the six patterns. Sprint is for speed — it doesn't change your Mastery.

60Seconds
0Correct
0Streak

📇 Pattern deck

✅ = completed · 🔒 = locked

🎯 Skill coverage

💡 Drill guide

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.

✎ Practice — 18 multiple-choice questions

Across the six patterns and choosing patterns. Skills you get wrong come back more often. Missed questions are saved to Mistakes.

🧪 Practice Exam Mode ON. No choices shown — recall the answer, then reveal and self-mark.

📊 Practice stats

0Attempts
–Accuracy

🎯 Weakest skills

📋 Exam-style questions — 12 questions

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.

📋 Exam stats

0Attempts
–Average mark

ℹ️ About these questions

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.

🔄 Review — 10 traps + 6 memory triggers

Read these before your exam. Then look at Mistakes to see the ones you make.

10 traps to know

🧠 Memory triggers

Six one-liners to recite before your exam.

🎯 Your weakest skills

💔 Your logged mistakes

🏆 Mastery — revision checklist

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.

🏆 Module Mastered — 11.3 Build Lab complete!

Revision checklist

Skill grid

Mastered = 3+ attempts and at least 70% accuracy. Tap the status chip to override it.

➡️ Next up: Ship Lab

Join the patterns into complete answers to full scenarios, and check them against what a good answer shows.

📊 Overview

0Skills attempted
0Skills mastered

Topic 11 Path

11.1–11.2 Read Lab
📍 11.3 Build Lab (this page)
11.4 Ship Lab

💔 Mistakes

Your mistakes log

Every wrong Practice, Exam or Pattern Builder answer is saved here automatically.

📊 Progress

Progress dashboard

Your attempts, accuracy and mastery counts in the Build Lab.

Practice

0Attempts
–Accuracy

Exam

0Attempts
–Average

Focus recommendation

Weakest skills

🔖 Bookmarks

Bookmarked questions

Bookmark an exam question to save it here.

📝 My Notes

My notes

Jot notes as you learn. Everything here is saved on this device only.

Add a note

Notes on this page (saved on this device only)

Quick stats

0Notes saved
0Page notes
🗄️ Vault

Your knowledge vault

Sent mistakes and saved key facts, in one place.

Saved ✓