What you'll learn
This revision guide covers the three fundamental programming constructs you must understand for CIE IGCSE Computer Science: sequence, selection and iteration. You'll learn how to control program flow using IF statements, CASE/SWITCH structures, and three types of loops (FOR, WHILE, REPEAT-UNTIL). These constructs form the building blocks of all algorithms and programs you'll write in the exam.
Key terms and definitions
Sequence — instructions executed one after another in the order they appear in the program code
Selection — a programming construct that allows different paths of execution based on whether a condition is true or false
Iteration — repeated execution of a block of code, also known as looping
Condition — a Boolean expression that evaluates to either TRUE or FALSE, used to control selection and iteration structures
Count-controlled loop — iteration that repeats a fixed number of times, typically implemented using a FOR loop
Condition-controlled loop — iteration that continues while or until a specific condition is met, implemented using WHILE or REPEAT-UNTIL loops
Nested structure — a control structure placed inside another control structure, such as a loop within a loop or an IF statement inside another IF statement
Indentation — the spacing at the start of code lines that shows which statements belong to which control structure
Core concepts
Sequence
Sequence is the simplest programming construct where statements execute in order from top to bottom. Each instruction completes before the next begins.
Example in pseudocode:
INPUT Number1
INPUT Number2
Total ← Number1 + Number2
OUTPUT Total
The program:
- Accepts the first number
- Accepts the second number
- Calculates the sum
- Displays the result
Every line executes once, in order. Understanding sequence is essential because it's the default flow of any program. Even when you introduce selection and iteration, the code within those structures still follows sequential execution.
Selection: IF statements
IF statements allow programs to make decisions and execute different code based on conditions. The CIE IGCSE specification requires you to understand both simple and complex IF structures.
Simple IF statement:
IF condition THEN
statement(s)
ENDIF
The statements only execute when the condition is TRUE. If FALSE, the program skips to the line after ENDIF.
IF-ELSE statement:
IF condition THEN
statement(s)
ELSE
statement(s)
ENDIF
One set of statements executes when TRUE, another when FALSE. Every execution path goes through exactly one block.
Nested IF statement:
IF condition1 THEN
IF condition2 THEN
statement(s)
ENDIF
ENDIF
The inner IF only evaluates when the outer condition is TRUE. Nesting allows for complex decision-making but requires careful indentation.
IF-ELSEIF-ELSE statement:
IF condition1 THEN
statement(s)
ELSEIF condition2 THEN
statement(s)
ELSE
statement(s)
ENDIF
This structure tests multiple conditions in sequence. Only the first TRUE condition's statements execute. The ELSE provides a default action when all conditions are FALSE.
Selection: CASE/SWITCH statements
CASE statements (also called SWITCH in some languages) provide an efficient alternative to multiple IF-ELSEIF statements when comparing one variable against several possible values.
Structure:
CASE OF variable
value1: statement(s)
value2: statement(s)
value3: statement(s)
OTHERWISE: statement(s)
ENDCASE
Key characteristics:
- The variable is evaluated once
- Each case represents one possible value
- Only matching case executes
- OTHERWISE handles all unmatched values (like ELSE in IF statements)
- More readable than multiple IF statements for menu selections or category checking
Example use:
CASE OF grade
'A': OUTPUT "Excellent"
'B': OUTPUT "Good"
'C': OUTPUT "Satisfactory"
OTHERWISE: OUTPUT "Needs improvement"
ENDCASE
CASE statements work best with discrete values (characters, integers, strings) rather than ranges. For range checking (e.g., score > 70), IF-ELSEIF structures are more appropriate.
Iteration: FOR loops
FOR loops implement count-controlled iteration. Use them when you know exactly how many times to repeat code.
Structure:
FOR counter ← start TO end
statement(s)
NEXT counter
With step value:
FOR counter ← start TO end STEP increment
statement(s)
NEXT counter
How it works:
- Counter starts at the initial value
- Statements execute
- Counter increases by the step value (default is 1)
- Loop continues while counter ≤ end value
- Loop terminates when counter exceeds end value
Example counting down:
FOR count ← 10 TO 1 STEP -1
OUTPUT count
NEXT count
OUTPUT "Blast off!"
Key points:
- The counter variable automatically updates
- Loop body might not execute at all (if start > end when step is positive)
- Avoid manually changing the counter variable inside the loop
Iteration: WHILE loops
WHILE loops implement condition-controlled iteration where the condition is tested before each iteration.
Structure:
WHILE condition DO
statement(s)
ENDWHILE
Characteristics:
- Condition evaluates before each iteration
- If initially FALSE, loop body never executes
- Must contain code that eventually makes condition FALSE (to avoid infinite loops)
- Use when you don't know how many iterations are needed
Example:
password ← ""
WHILE password <> "secret" DO
OUTPUT "Enter password: "
INPUT password
ENDWHILE
OUTPUT "Access granted"
The loop continues until the correct password is entered. The number of attempts isn't predetermined.
Infinite loop prevention: Every WHILE loop needs a loop control variable that changes inside the loop to eventually make the condition FALSE:
count ← 1
total ← 0
WHILE count <= 5 DO
INPUT number
total ← total + number
count ← count + 1 // Essential: moves toward termination
ENDWHILE
Iteration: REPEAT-UNTIL loops
REPEAT-UNTIL loops implement condition-controlled iteration where the condition is tested after each iteration.
Structure:
REPEAT
statement(s)
UNTIL condition
Critical differences from WHILE:
- Condition tests at the end
- Loop body always executes at least once
- Continues while condition is FALSE
- Stops when condition becomes TRUE
Example:
REPEAT
OUTPUT "Enter a number between 1 and 10: "
INPUT number
UNTIL number >= 1 AND number <= 10
This ensures the user is prompted at least once, continuing until valid input is received.
WHILE vs REPEAT-UNTIL decision:
- Use WHILE when the loop might not need to execute at all
- Use REPEAT-UNTIL when the loop must execute at least once (like input validation)
- WHILE continues while TRUE; REPEAT-UNTIL continues while FALSE
Nested iteration
Nested loops occur when one loop is placed inside another. The inner loop completes all its iterations for each single iteration of the outer loop.
Example (times table):
FOR row ← 1 TO 12
FOR column ← 1 TO 12
result ← row * column
OUTPUT result
NEXT column
OUTPUT "" // New line after each row
NEXT row
For row = 1, the inner loop runs 12 times. For row = 2, it runs 12 times again. Total iterations: 12 × 12 = 144.
Applications:
- Processing 2D arrays or grids
- Generating combinations
- Searching within categories
- Complex pattern printing
Worked examples
Example 1: Input validation with REPEAT-UNTIL
Question: Write an algorithm that asks a user to enter their age. The program should reject any value less than 0 or greater than 120, and continue asking until valid input is received. (4 marks)
Solution:
REPEAT
OUTPUT "Please enter your age: "
INPUT age
IF age < 0 OR age > 120 THEN
OUTPUT "Invalid age. Try again."
ENDIF
UNTIL age >= 0 AND age <= 120
OUTPUT "Age accepted: ", age
Mark scheme:
- REPEAT-UNTIL structure (1 mark)
- Correct condition testing age range (1 mark)
- Appropriate INPUT and OUTPUT statements (1 mark)
- Error message for invalid input (1 mark)
Example 2: Menu system with CASE statement
Question: A coffee shop program uses a CASE statement to calculate prices. Write pseudocode that inputs a drink code ('E' for Espresso £2.50, 'L' for Latte £3.00, 'C' for Cappuccino £3.25, 'A' for Americano £2.75) and outputs the price. Include an OTHERWISE clause for invalid codes. (5 marks)
Solution:
INPUT drinkCode
CASE OF drinkCode
'E': price ← 2.50
'L': price ← 3.00
'C': price ← 3.25
'A': price ← 2.75
OTHERWISE:
OUTPUT "Invalid code"
price ← 0
ENDCASE
IF price > 0 THEN
OUTPUT "Price: £", price
ENDIF
Mark scheme:
- Correct CASE structure with ENDCASE (1 mark)
- All four drink codes with correct prices (1 mark)
- OTHERWISE clause (1 mark)
- Appropriate INPUT statement (1 mark)
- Meaningful price output (1 mark)
Example 3: Nested loops for pattern generation
Question: Write an algorithm using nested FOR loops to output the following pattern:
*
**
***
****
*****
(4 marks)
Solution:
FOR row ← 1 TO 5
FOR column ← 1 TO row
OUTPUT "*"
NEXT column
OUTPUT "" // Move to new line
NEXT row
Mark scheme:
- Outer FOR loop with correct range (1 mark)
- Inner FOR loop with variable end point related to outer counter (1 mark)
- Correct output of asterisk character (1 mark)
- New line output between rows (1 mark)
Common mistakes and how to avoid them
Confusing WHILE and REPEAT-UNTIL conditions: WHILE loops continue when the condition is TRUE; REPEAT-UNTIL loops continue when the condition is FALSE. Always check which type terminates the loop.
Forgetting to update loop control variables: In WHILE loops, you must manually change the variable that affects the condition. Without this, you create an infinite loop. Always include statements that move toward the termination condition.
Using CASE statements for range checking: CASE statements compare exact values only. Use IF-ELSEIF for conditions like "score > 70" or "age >= 18". Reserve CASE for discrete categories like menu options or grade letters.
Incorrect indentation hiding logic errors: Indentation shows which statements belong to which structure. Misaligned code might appear correct but execute in the wrong order. Indent consistently: all statements in a structure should align vertically.
Off-by-one errors in FOR loops: "FOR i ← 1 TO 10" executes 10 times (values 1, 2, 3...10), not 9 times. "FOR i ← 0 TO 9" also executes 10 times. Count carefully when the loop starts at 0 or uses STEP values.
Nested loop counter confusion: Never use the same variable name for inner and outer loop counters. Use meaningful names like "row" and "column" rather than reusing generic names like "count".
Exam technique for Programming concepts: sequence, selection and iteration constructs
"Write an algorithm" questions: Use proper pseudocode syntax as specified in CIE documentation. Include START/END markers if required by the question. Use correct keywords (IF-THEN-ELSE-ENDIF, FOR-NEXT, WHILE-ENDWHILE, REPEAT-UNTIL, CASE-ENDCASE). Indent code clearly to show structure hierarchy.
Command word "State": Requires a brief precise answer without explanation. Example: "State the type of loop" expects "count-controlled" or "condition-controlled", not a description of how it works.
"Identify" or "Complete" pseudocode questions: Read the entire code first to understand its purpose. Check that variables are initialized before use. Ensure loop termination conditions are logically correct. Verify that selection conditions match the described outcome. Usually worth 2-3 marks per gap.
Trace table questions: Execute code line by line, updating variable values systematically. Show all iterations clearly. Mark examiners award marks for correct intermediate values, not just final answers. Condition-controlled loops are common in trace table questions—watch for termination carefully.
Quick revision summary
Programs use three control structures: sequence (instructions execute in order), selection (IF or CASE statements choose execution paths based on conditions), and iteration (FOR, WHILE, or REPEAT-UNTIL loops repeat code). FOR loops are count-controlled for known repetitions. WHILE loops test conditions before execution and might not run at all. REPEAT-UNTIL loops test after execution and always run at least once. CASE statements efficiently handle multiple exact value comparisons. Structures can nest, creating complex logic. Always ensure loops can terminate to avoid infinite execution.