Programming Constructs (Sequence, Selection, Iteration)

    Master the core building blocks of programming for your WJEC GCSE Computer Science exam. This guide breaks down Sequence, Selection, and Iteration with examiner insights, worked examples, and interactive content to help you write flawless code and secure top marks.

    7
    Min Read
    3
    Examples
    5
    Questions
    0
    Key Terms
    🎙 Podcast Episode
    Programming Constructs (Sequence, Selection, Iteration)
    0:00-0:00

    Study Notes

    header_image.png

    Overview

    Welcome to the heart of programming! This guide focuses on Programming Constructs (WJEC Specification 5.1), the fundamental logic that powers every piece of software. These constructs are the rules that tell a computer not just what to do, but in what order, when to make choices, and how many times to repeat an action. For your WJEC GCSE, mastering Sequence, Selection, and Iteration is non-negotiable. It accounts for a huge portion of the marks in both the Unit 1 written paper and the Unit 2 on-screen practical exam. You will be asked to read, write, and debug algorithms using these constructs in both pseudocode and a high-level language (like Python or Java). This topic is the foundation upon which all your other programming skills are built, linking directly to data structures, subroutines, and file handling. Expect questions that require you to trace code, design algorithms from scratch, and justify your choice of construct.

    programming_constructs_podcast.mp3

    Key Concepts

    At its core, an algorithm is just a set of instructions. Programming constructs are the tools we use to structure those instructions logically.

    sequence_selection_iteration_diagram.png

    Concept 1: Sequence

    Sequence is the most straightforward construct. It means that instructions are executed one after another, in the precise order they are written, from top to bottom. There are no jumps, no skipped steps, and no repetitions. Think of it like a recipe: you must complete each step in order to get the correct result.

    Why it works: Computers are inherently sequential machines. The processor fetches an instruction, executes it, and moves to the next one in memory. Sequence is the default behaviour.

    Example: A program to calculate the area of a rectangle.

    1. INPUT width
    2. INPUT height
    3. area = width * height
    4. OUTPUT area

    Each instruction is executed in a strict, linear order. A common place candidates lose marks is by trying to use a variable before it has been given a value (e.g., putting line 3 before lines 1 and 2). This is a fundamental sequence error. Credit is awarded for correctly initializing variables before they are used in calculations or loops.

    Concept 2: Selection

    Selection allows a program to make decisions. It uses a condition (a statement that evaluates to either True or False) to decide which block of code to execute. This allows the program to follow different paths based on input or changing circumstances. The primary tool for selection is the IF statement.

    Why it works: Selection is based on Boolean logic. The condition is evaluated, and the result determines the flow of execution. This is fundamental to creating responsive and intelligent programs.

    Types of Selection:

    • IF...THEN...END IF: Executes a block of code only if the condition is true.
      pseudocode
      IF age >= 18 THEN
      OUTPUT "You can vote."
      END IF

    • IF...THEN...ELSE...END IF: Provides two possible paths. One for when the condition is true, and another (the ELSE block) for when it is false.
      pseudocode
      IF temp > 20 THEN
      OUTPUT "It is warm."
      ELSE
      OUTPUT "It is cold."
      END IF

    • IF...ELSE IF...ELSE...END IF: Used for multiple, mutually exclusive conditions. This is more efficient than using multiple separate IF statements, as the computer stops checking as soon as it finds a true condition.
      pseudocode
      IF score > 80 THEN
      OUTPUT "Grade A"
      ELSE IF score > 60 THEN
      OUTPUT "Grade B"
      ELSE
      OUTPUT "Grade C"
      END IF

    Nested Selection: You can place IF statements inside other IF statements to create more complex logic. This is powerful but requires careful indentation and structure to remain readable. Examiners look for clear nesting in 6-mark algorithm questions.

    nested_selection_flowchart.png

    Concept 3: Iteration

    Iteration means repeating a block of code. This is also known as looping. Iteration is essential for processing collections of data, performing actions multiple times, or waiting for an event to occur. There are two main categories of iteration.

    1. Count-Controlled Iteration:
    This is used when you know in advance exactly how many times you need to repeat the code. The FOR loop is the primary example.

    Example: Output the numbers from 1 to 10.
    pseudocode
    FOR i = 1 TO 10
    OUTPUT i
    NEXT i

    This loop will execute precisely 10 times. Marks are often awarded for correctly defining the start and end points of the loop. Be careful of 'off-by-one' errors, where the loop runs one too many or one too few times.

    2. Condition-Controlled Iteration:
    This is used when the number of repetitions is not known in advance. The loop continues as long as a certain condition is met. There are two types:

    • WHILE Loop (Pre-condition): The condition is checked before the loop body is executed. If the condition is false at the very beginning, the loop will not execute at all.
      pseudocode
      count = 1
      WHILE count <= 5
      OUTPUT count
      count = count + 1
      END WHILE

    • REPEAT...UNTIL Loop (Post-condition): The loop body is executed before the condition is checked. This means the loop will always execute at least once.
      pseudocode
      count = 1
      REPEAT
      OUTPUT count
      count = count + 1
      UNTIL count > 5

    loop_comparison_diagram.png

    An infinite loop is a common error where the loop's exit condition is never met. For example, if you forget count = count + 1 in the WHILE loop above, count will always be 1, the condition count <= 5 will always be true, and the loop will run forever. Examiners specifically look for a valid termination condition in your code.

    Mathematical/Scientific Relationships

    While programming constructs are logical, they are often used to implement mathematical relationships. The key is in the operators used within selection and iteration conditions.

    • Relational Operators: Used to compare values.
      • == (Equal to)
      • != or <> (Not equal to)
      • > (Greater than)
      • < (Less than)
      • >= (Greater than or equal to)
      • <= (Less than or equal to)
    • Logical Operators: Used to combine multiple conditions.
      • AND: Both conditions must be true (e.g., IF age >= 18 AND hasLicense == true).
      • OR: At least one condition must be true (e.g., IF day == "Saturday" OR day == "Sunday" ).
      • NOT: Inverts the result of a condition (e.g., IF NOT isRaining).

    Credit is given for selecting the correct relational operator to accurately model the problem described in an exam question.

    Practical Applications

    • Sequence: Any step-by-step process, like a login sequence (enter username, then enter password, then click submit).
    • Selection: Validating user input (e.g., IF password is less than 8 characters, show an error). Or in a game, IF player health is 0, trigger the 'Game Over' sequence.
    • Iteration: A FOR loop could be used to process every pixel in an image. A WHILE loop could be the main game loop, running continuously WHILE the player is alive. A REPEAT...UNTIL loop is great for menus, where you want to display the options at least once and keep showing them UNTIL the user chooses to exit.

    Worked Examples

    3 detailed examples with solutions and examiner commentary

    Practice Questions

    Test your understanding — click to reveal model answers

    Q1

    A user enters their password. Write a pseudocode algorithm that checks if the password is exactly equal to "Secret123". If it is, output "Access granted"; otherwise, output "Access denied".

    3 marks
    foundation

    Hint: You will need one selection statement and a condition that compares two strings.

    Q2

    Write a pseudocode algorithm that asks the user to enter 5 numbers and then outputs the total of those 5 numbers.

    4 marks
    standard

    Hint: Use a count-controlled loop (`FOR`) and a variable to keep a running total.

    Q3

    A simple game asks a user to guess a secret number, which is 42. The program should repeatedly ask for a guess until the user gets it right. For each wrong guess, it should tell them if their guess was too high or too low. When they guess correctly, it should output "Correct!".

    6 marks
    challenging

    Hint: You'll need a condition-controlled loop (`WHILE` or `REPEAT`) that continues until the guess is correct. Inside the loop, you'll need a nested selection statement.

    Q4

    Describe the main difference between a count-controlled loop and a condition-controlled loop. Give an example of a situation where each would be used.

    4 marks
    standard

    Hint: Think about when you know the number of repetitions versus when you don't.

    Q5

    Identify the error in the following pseudocode, which is intended to print the numbers 1, 2, 3, 4, 5.

    2 marks
    foundation

    Hint: Look at what happens to the `counter` variable. Does it ever change?

    More Computer Science Study Guides

    View all

    Problem Decomposition

    Edexcel
    GCSE

    Master Problem Decomposition for your Edexcel GCSE Computer Science exam. This guide breaks down how to deconstruct complex problems into simple, manageable parts—a core skill for top marks in computational thinking and a fundamental concept for all future programming.

    Programming Fundamentals

    Edexcel
    GCSE

    Master the core of programming for your Edexcel GCSE Computer Science exam. This guide breaks down variables, control structures, and data types into easy-to-understand concepts, focusing on the practical Python skills needed to excel in Paper 2.

    Network Topologies

    AQA
    GCSE

    Master AQA GCSE Network Topologies (4.1) by understanding the critical differences between Star and Mesh layouts. This guide breaks down how each topology works, their real-world applications, and exactly what examiners are looking for to award you maximum marks.

    Algorithms

    OCR
    A-Level

    Master OCR A-Level Computer Science Algorithms (2.1) with this comprehensive guide. We'll break down algorithm analysis using Big O notation, explore standard sorting and searching algorithms, and demystify pathfinding with Dijkstra's and A*. This guide is packed with exam-focused advice, worked examples, and memory hooks to help you secure top marks.

    Data representation

    OCR
    GCSE

    This guide demystifies how computers represent everything from numbers to images and sound using only binary. Master the core concepts of data representation for your OCR GCSE Computer Science exam and learn how to secure top marks with examiner insights and multi-modal resources.

    Programming fundamentals

    Edexcel
    GCSE

    Master the core of coding for your Edexcel GCSE Computer Science exam. This guide breaks down Programming Fundamentals (2.2), showing you how to write, debug, and perfect Python code for sequence, selection, and iteration to secure top marks in your Paper 2 onscreen exam.