Every algorithm can be written using just three fundamental constructs. These are the building blocks of all programs in OCR J277.
Sequence
Instructions executed one after another, in order
Selection
A decision — different code runs depending on a condition
Iteration
Repetition — a block of code runs multiple times
1. Sequence
The simplest construct. Lines of code execute one after another, top to bottom, in the order they are written. There is no branching or repetition.
// Sequence example — runs in order, line by line name = input("Enter name: ") age = int(input("Enter age: ")) OUTPUT"Hello, " + name OUTPUT"You are " + str(age) + " years old"
2. Selection — IF…THEN…ELSE
Selection uses a condition to decide which branch of code to execute. The condition evaluates to True or False.
// Simple IF IF score >= 50THEN OUTPUT"Pass" END IF
// IF…ELSE IF score >= 50THEN OUTPUT"Pass" ELSE OUTPUT"Fail" END IF
// IF…ELSE IF…ELSE (nested) IF score >= 70THEN OUTPUT"Distinction" ELSE IF score >= 50THEN OUTPUT"Pass" ELSE OUTPUT"Fail" END IF
3. Iteration — FOR Loops (Count-Controlled)
A FOR loop repeats a block a known, fixed number of times. The loop counter increments automatically.
// FOR loop — runs exactly 5 times (1, 2, 3, 4, 5) FOR i = 1TO5 OUTPUT i NEXT i
// FOR loop counting down FOR i = 10TO1STEP -1 OUTPUT i NEXT i
4. Iteration — WHILE Loops (Condition-Controlled)
A WHILE loop repeats while a condition is True. The condition is tested before each iteration. If the condition is False at the start, the loop body never executes.
// WHILE loop — repeats until password is correct password = "" WHILE password != "secret"
password = input("Enter password: ") END WHILE OUTPUT"Access granted"
5. Iteration — DO…UNTIL Loops
A DO…UNTIL loop always executes at least once, because the condition is checked after each iteration. Continues until the condition becomes True.
// DO…UNTIL — always runs at least once DO
answer = int(input("Guess (1-10): ")) UNTIL answer == 7 OUTPUT"Correct!"
Comparing the Loops
Loop type
When to use
Condition checked
Min. runs
FOR
Known number of iterations
Before each iteration
0 (if range empty)
WHILE
Unknown iterations; check first
Before each iteration
0 (if condition false)
DO…UNTIL
Must run at least once
After each iteration
1 always
Nested Constructs
Constructs can be nested inside each other — e.g. a FOR loop inside a FOR loop (2D iteration), or an IF inside a WHILE loop.
// Nested FOR loops — multiplication table FOR i = 1TO3 FOR j = 1TO3 OUTPUT i * j NEXT j NEXT i
Exam tip: Key exam questions on this topic: (1) "Name the programming construct that..." — know sequence/selection/iteration definitions cold. (2) "Which loop would you use when the number of iterations is not known?" — WHILE or DO…UNTIL. (3) "What is the difference between WHILE and DO…UNTIL?" — WHILE checks condition first (may run 0 times); DO…UNTIL checks after (always runs at least once). (4) Writing pseudocode: always use correct OCR J277 syntax with END IF, END WHILE, NEXT.
⚠️ Common Mistakes
Forgetting END IF, END WHILE, or NEXT i — these close the block; always include them
Using a FOR loop when the number of iterations is unknown — use WHILE or DO…UNTIL
Confusing WHILE (check first) and DO…UNTIL (check after) — a WHILE may run 0 times
Off-by-one errors in FOR loops: FOR i = 1 TO 5 runs 5 times (1,2,3,4,5) not 4
Writing IF without END IF — always close your selection block
Q1Name the three programming constructs and give a one-sentence definition of each.[3]
✅ Mark scheme
Sequence: instructions executed one after another in order [1]. Selection: a condition is evaluated and different code runs depending on whether it is True or False (IF…THEN…ELSE) [1]. Iteration: a block of code is repeated — either a fixed number of times (FOR) or while a condition holds (WHILE/DO…UNTIL) [1].
Q2Write pseudocode using a FOR loop to output the numbers 1 to 10.[2]
✅ Mark scheme
FOR i = 1 TO 10 [1]; OUTPUT i; NEXT i [1]. Award marks for correct loop bounds and closing NEXT statement.
Q3Explain the difference between a WHILE loop and a DO…UNTIL loop.[2]
✅ Mark scheme
A WHILE loop tests the condition before each iteration — if the condition is False from the start, the body never executes (0 runs possible) [1]. A DO…UNTIL loop tests the condition after each iteration — the body always runs at least once [1].
Q4Write pseudocode to ask the user to enter a number between 1 and 10. Keep asking until they enter a valid number.[3]
✅ Mark scheme
DO [1]; num = int(input("Enter a number (1-10): ")); UNTIL num >= 1 AND num <= 10 [2]. Accept WHILE equivalent with appropriate condition. Award 1 mark for loop structure, 1 for input, 1 for correct condition.
Q5Write pseudocode to output grades based on a score. 70+ = A, 50-69 = B, below 50 = C.[4]
✅ Mark scheme
IF score >= 70 THEN [1]; OUTPUT "A" [1]; ELSE IF score >= 50 THEN; OUTPUT "B" [1]; ELSE; OUTPUT "C"; END IF [1]. Must use nested IF/ELSE IF structure. Award marks for correct thresholds and output.
Q6How many times does this loop execute? FOR i = 3 TO 9 STEP 2[2]
✅ Mark scheme
4 times [1]: i = 3, 5, 7, 9 [1]. STEP 2 means the counter increases by 2 each iteration.
Q7A game loop should keep running while the player has lives > 0 and the game is not won. Write the WHILE condition.[2]
✅ Mark scheme
WHILE lives > 0 AND gameWon == False [1] (or NOT gameWon) [1]. Both conditions must be present with AND. Award 1 for each correct condition.
Q8A FOR loop inside another FOR loop is called a nested loop. How many times does the inner body run in: FOR i = 1 TO 4; FOR j = 1 TO 3; [body]; NEXT j; NEXT i?[2]
✅ Mark scheme
12 times [1]. The inner loop (j: 1 to 3) runs 3 times per outer iteration. The outer loop (i: 1 to 4) runs 4 times. Total: 4 × 3 = 12 [1].
?
out of 20 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 10
Click to reveal definition
🎉
Complete!
Term
Definition
🎯
Mini Test — 2.2.1c Sequence, Selection & Iteration
10 questions · 10 marks · 10 minutes
⏱ 10:00
10 marks
Section A — Multiple Choice [5 marks]
Q1Which loop is best when the number of iterations is known in advance?
Q2A DO...UNTIL loop always runs at least how many times?
Q3How many times does FOR i = 1 TO 5 execute?
Q4Which construct is used to run different code based on a condition?
Q5A WHILE loop with a condition that is False from the start will run how many times?
Section B — Short Answer [5 marks]
Q6Name the three programming constructs and explain what each one does.
Mark schemeSequence: instructions run one after another in order [1]. Selection (IF): different code runs depending on whether a condition is True or False [1]. Iteration (loop): a block of code repeats either a fixed number of times or while a condition is met [1].
Q7Write pseudocode to output the sum of all integers from 1 to 100 using a FOR loop.
Mark schemetotal = 0 [1]; FOR i = 1 TO 100 [1]; total = total + i; NEXT i; OUTPUT total [1].
Q8Explain why a DO...UNTIL loop is more suitable than a WHILE loop when you need a menu to be shown at least once.
Mark schemeA DO...UNTIL loop always executes at least once before checking the condition [1] — so the menu will always be displayed. A WHILE loop checks the condition first and might not execute at all if the condition is already False [1].
Q9How many total iterations occur in: FOR i = 1 TO 3; FOR j = 1 TO 4; [body]; NEXT j; NEXT i?
Mark scheme12 iterations [1]. Outer loop runs 3 times (i = 1, 2, 3). For each, the inner loop runs 4 times (j = 1, 2, 3, 4). Total = 3 × 4 = 12 [1].
Q10A student writes "IF score > 50 THEN OUTPUT Pass END IF". What is missing and what would happen without it?
Mark schemeThe ELSE branch is missing [1]. Without ELSE, there is no output when score is 50 or below — the program simply skips to the next line without any output for the failing case [1].