What you'll learn
This guide covers the three fundamental programming constructs essential for algorithm design: sequence, selection and iteration. You'll learn how to express algorithms using both CIE pseudocode and flowcharts, understand when to apply each construct, and develop solutions to computational problems that meet exam standard.
Key terms and definitions
Algorithm — a precise, step-by-step set of instructions designed to solve a specific problem or perform a task
Sequence — instructions executed one after another in a specific order, the most basic programming construct
Selection — a construct that allows a program to choose between different paths based on a condition (also called conditional statements or branching)
Iteration — repetition of a set of instructions either a specific number of times or until a condition is met (also called loops)
Pseudocode — a structured, language-independent way of representing algorithms using plain English-like statements and CIE-specified syntax
Flowchart — a visual diagram using standardised symbols and arrows to represent the flow of control through an algorithm
Boolean expression — a condition that evaluates to either TRUE or FALSE, used in selection and iteration constructs
Trace table — a method of dry running an algorithm by recording how variable values change with each instruction
Core concepts
Sequence construct
Sequence is the simplest programming construct where instructions execute in the exact order they are written, from top to bottom.
In pseudocode, sequence appears as one statement per line:
INPUT Age
Total ← Age + 5
OUTPUT Total
In flowcharts, sequence is shown using rectangular process boxes connected by arrows flowing downward:
- Parallelograms represent INPUT/OUTPUT operations
- Rectangles represent process steps (assignments, calculations)
- Arrows show the direction of flow
Every algorithm contains sequence — even complex programs with selection and iteration still execute their component parts sequentially.
Key characteristics:
- No decisions or repetition
- Predictable execution order
- Each instruction executes exactly once
- Cannot skip or repeat instructions
Selection construct: IF statements
Selection allows programs to make decisions and execute different code based on whether conditions are TRUE or FALSE.
IF...THEN...ENDIF structure:
IF condition THEN
statement(s)
ENDIF
Example:
IF Age >= 18 THEN
OUTPUT "Adult"
ENDIF
IF...THEN...ELSE...ENDIF structure:
IF condition THEN
statement(s)
ELSE
statement(s)
ENDIF
Example:
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
Nested IF statements allow multiple levels of decision-making:
IF Temperature > 30 THEN
OUTPUT "Hot"
ELSE
IF Temperature > 20 THEN
OUTPUT "Warm"
ELSE
OUTPUT "Cold"
ENDIF
ENDIF
Flowchart representation:
- Diamond-shaped decision boxes contain the condition
- Two arrows exit: one labelled "Yes" or "True", one labelled "No" or "False"
- Different paths merge back together after the selection
Selection construct: CASE statements
The CASE statement (also called SWITCH in some languages) provides a cleaner way to handle multiple specific values:
CASE OF variable
value1 : statement(s)
value2 : statement(s)
value3 : statement(s)
OTHERWISE statement(s)
ENDCASE
Example:
CASE OF Grade
'A' : OUTPUT "Excellent"
'B' : OUTPUT "Good"
'C' : OUTPUT "Satisfactory"
OTHERWISE OUTPUT "Needs improvement"
ENDCASE
Use CASE when:
- Testing one variable against multiple specific values
- The values are discrete (not ranges)
- Code clarity is important
Use IF when:
- Testing complex conditions or ranges
- Comparing different variables
- Using relational operators (<, >, <=, >=)
Iteration construct: count-controlled loops
FOR loops execute a known number of times using a counter variable:
FOR counter ← start TO end
statement(s)
NEXT counter
Example:
FOR Count ← 1 TO 10
OUTPUT Count
NEXT Count
Step values allow counting by amounts other than 1:
FOR Count ← 0 TO 100 STEP 5
OUTPUT Count
NEXT Count
This outputs: 0, 5, 10, 15... 100
Counting backwards:
FOR Count ← 10 TO 1 STEP -1
OUTPUT Count
NEXT Count
Flowchart representation:
- Use a process box to initialise the counter
- Diamond decision box tests if counter has reached the limit
- Process boxes contain the loop body
- Process box increments the counter
- Arrow loops back to the decision
Iteration construct: condition-controlled loops
WHILE loops repeat as long as a condition remains TRUE (pre-condition loop):
WHILE condition DO
statement(s)
ENDWHILE
Example:
Total ← 0
Number ← 1
WHILE Number <= 100 DO
Total ← Total + Number
Number ← Number + 1
ENDWHILE
REPEAT...UNTIL loops repeat until a condition becomes TRUE (post-condition loop):
REPEAT
statement(s)
UNTIL condition
Example:
REPEAT
INPUT Password
UNTIL Password = "Secret123"
Key differences:
- WHILE tests the condition before executing the loop body (may execute zero times)
- REPEAT tests the condition after executing the loop body (always executes at least once)
- WHILE continues when condition is TRUE; REPEAT continues when condition is FALSE
Infinite loops occur when the loop condition never becomes FALSE (WHILE) or TRUE (REPEAT):
WHILE TRUE DO
OUTPUT "Forever"
ENDWHILE
Avoid infinite loops by ensuring:
- The condition can change
- Variables in the condition are modified within the loop
- Loop logic is correct
Combining constructs
Real algorithms combine sequence, selection and iteration to solve complex problems.
Nested loops place one loop inside another:
FOR Row ← 1 TO 5
FOR Col ← 1 TO 3
OUTPUT "*"
NEXT Col
OUTPUT newline
NEXT Row
This produces a 5×3 grid of asterisks.
Selection within loops:
Total ← 0
FOR Count ← 1 TO 10
INPUT Number
IF Number > 0 THEN
Total ← Total + Number
ENDIF
NEXT Count
OUTPUT Total
Loops within selection:
INPUT Choice
IF Choice = "Table" THEN
FOR Count ← 1 TO 12
OUTPUT Count * 7
NEXT Count
ENDIF
Worked examples
Example 1: Grade classifier using selection
Question: Write pseudocode that inputs a test mark (0-100) and outputs the grade according to these boundaries: A (70+), B (60-69), C (50-59), D (40-49), E (below 40).
Solution:
INPUT Mark
IF Mark >= 70 THEN
OUTPUT "Grade A"
ELSE
IF Mark >= 60 THEN
OUTPUT "Grade B"
ELSE
IF Mark >= 50 THEN
OUTPUT "Grade C"
ELSE
IF Mark >= 40 THEN
OUTPUT "Grade D"
ELSE
OUTPUT "Grade E"
ENDIF
ENDIF
ENDIF
ENDIF
Mark scheme points:
- Correct INPUT statement (1 mark)
- Appropriate use of nested IF structure (1 mark)
- Correct boundaries in conditions (1 mark)
- All five grades output correctly (1 mark)
Example 2: Finding maximum value using iteration
Question: Write pseudocode that inputs 20 numbers and outputs the largest value entered.
Solution:
Maximum ← 0
FOR Count ← 1 TO 20
INPUT Number
IF Number > Maximum THEN
Maximum ← Number
ENDIF
NEXT Count
OUTPUT "Largest value: ", Maximum
Mark scheme points:
- Variable initialised to store maximum (1 mark)
- FOR loop with correct range (1 mark)
- INPUT inside loop (1 mark)
- Comparison updates maximum when appropriate (1 mark)
- OUTPUT after loop completes (1 mark)
Note: Initialising Maximum to 0 assumes all numbers are positive. For a complete solution handling negative numbers, initialise to a very small value or to the first input.
Example 3: Validation using REPEAT...UNTIL
Question: Draw a flowchart that repeatedly asks a user to enter a PIN until they enter the correct value "1234". After three failed attempts, output "Account locked" and stop.
Solution:
A flowchart showing:
- Parallelogram: "Attempts ← 0"
- Parallelogram: "INPUT PIN"
- Parallelogram: "Attempts ← Attempts + 1"
- Diamond: "PIN = '1234'"
- Yes arrow → Parallelogram: "OUTPUT 'Access granted'" → Terminator
- No arrow continues
- Diamond: "Attempts = 3"
- Yes arrow → Parallelogram: "OUTPUT 'Account locked'" → Terminator
- No arrow loops back to step 2
Mark scheme points:
- Correct flowchart symbols used (1 mark)
- Counter initialised and incremented (1 mark)
- PIN comparison in decision box (1 mark)
- Attempts limit checked correctly (1 mark)
- Appropriate loop structure (1 mark)
- Clear flow with arrows (1 mark)
Common mistakes and how to avoid them
Confusing assignment with comparison: Use
←for assignment (storing values) and=for comparison (testing equality). The statementTotal ← Total + 1is assignment;IF Total = 10 THENis comparison.Incorrect loop boundaries: Remember FOR loops are inclusive.
FOR Count ← 1 TO 10executes 10 times (1, 2, 3...10), not 9 times. Count carefully when the loop must execute a specific number of times.WHILE vs REPEAT confusion: WHILE checks the condition first (might not execute); REPEAT checks after (always executes once). Choose REPEAT when the loop body must run at least once, such as input validation.
Missing ENDIF, ENDWHILE, NEXT statements: Every IF needs ENDIF, every WHILE needs ENDWHILE, every FOR needs NEXT. Examiners penalise incomplete structures. Indent your code to spot missing closures.
Using wrong flowchart symbols: Parallelograms are for INPUT/OUTPUT only; rectangles are for processes; diamonds are for decisions. Using a rectangle for INPUT loses marks.
Not initialising variables: Before using counters or totals in loops, initialise them:
Total ← 0before accumulating. Uninitialised variables lead to logic errors and lost marks.
Exam technique for Algorithm design and problem-solving: pseudocode and flowcharts — sequence, selection and iteration constructs
Read command words carefully: "Write" means pseudocode using CIE syntax; "Draw" means a flowchart with correct symbols; "Complete" means filling gaps in existing code; "Identify" means stating which construct is used without writing code.
Show your working: In algorithm questions, partial marks are available for correct structure even if logic is imperfect. Write clear, properly indented pseudocode. In flowcharts, use a ruler and draw clear arrows.
Match the mark allocation: A 6-mark question requires approximately six distinct correct elements. Don't write 20 lines for 3 marks or 3 lines for 8 marks. Plan before writing.
Validate your solution: After writing pseudocode or drawing a flowchart, trace through it with sample data mentally. Does it produce the correct output? Does it handle edge cases? This catches errors before submitting.
Quick revision summary
Algorithms use three fundamental constructs: sequence (ordered steps), selection (IF/CASE decisions based on conditions), and iteration (FOR/WHILE/REPEAT loops). Express algorithms using CIE pseudocode syntax with proper keywords and indentation, or flowcharts using standard symbols (parallelogram for input/output, rectangle for process, diamond for decision). FOR loops repeat a known number of times; WHILE loops check conditions first; REPEAT loops check after. Always initialise variables, close all structures correctly, and trace your logic with test data.