Constructs

    Edexcel
    GCSE
    Computer Science

    Master the fundamental building blocks of all software: Sequence, Selection, and Iteration. This topic is the core of Computer Science and tests your ability to think like a real programmer, enabling you to read, trace, and write code confidently for the exam.

    4
    Min Read
    3
    Examples
    5
    Questions
    6
    Key Terms
    🎙 Podcast Episode
    Constructs
    0:00-0:00

    Study Notes

    Overview

    Programming Constructs Overview

    Welcome to Programming Constructs! This topic is the beating heart of Computer Science. Whether you are building a simple calculator or the software that runs a Mars rover, every single program is built from just three fundamental structural components: Sequence, Selection, and Iteration.

    Understanding these constructs is crucial because examiners don't just want you to memorise definitions; they want to see you apply them to solve problems. This topic connects deeply to algorithms, data representation, and computational thinking. Typical exam questions will ask you to write code snippets, trace algorithms using trace tables, or identify logic errors where these constructs have been used incorrectly.

    Key Concepts

    Concept 1: The Three Core Constructs

    Every program relies on these three building blocks. Examiners expect you to identify them and use them appropriately.

    The Three Core Constructs

    1. Sequence: This is the default behaviour of a program. Instructions are executed one after another, in the exact order they are written, from top to bottom. If you write print("A") before print("B"), "A" will always appear first.
    2. Selection: This allows a program to make decisions. It uses conditions (which evaluate to True or False) to determine which path of code to execute. We typically use if, elif, and else statements. Think of it like a fork in the road.
    3. Iteration: This is looping—repeating a block of code. There are two main types you must master:
      • Count-controlled iteration (for loops): Used when you know exactly how many times the code needs to repeat.
      • Condition-controlled iteration (while loops): Used when you don't know how many times the code needs to repeat; it loops until a condition becomes False.

    Concept 2: Variables and Constants

    Programs need to store data while they run.

    • A variable is a named memory location whose value can change while the program is running (e.g., playerScore = 10).
    • A constant is a named memory location whose value cannot change while the program is running (e.g., PI = 3.14159).

    Why use constants? They make code more readable and easier to maintain. If a fixed value changes in the future (like a VAT rate), you only have to update it in one place at the top of your code, rather than hunting through hundreds of lines.

    Concept 3: Subprograms (Procedures vs Functions)

    As programs get larger, they become harder to read and debug. We solve this by breaking them down into smaller, reusable blocks called subprograms.

    Procedures vs Functions

    There is a critical distinction examiners test every year:

    • Procedures: Perform a specific task but do not return a value to the main program. (e.g., clearing the screen).
    • Functions: Perform a specific task and return a value to the main program using a return statement. (e.g., calculating an area and returning the result).

    Both can accept parameters—values passed into the subprogram to give it the data it needs to work.

    Concept 4: Variable Scope (Global vs Local)

    Where you declare a variable determines where it can be used.

    Global vs Local Variable Scope

    • Global Variables: Declared outside any subprogram. They can be accessed and modified from anywhere in the entire program.
    • Local Variables: Declared inside a specific subprogram. They can only be accessed within that subprogram and are destroyed when the subprogram finishes running.

    Examiner Tip: Always prefer local variables! They keep subprograms self-contained and prevent accidental changes to data from other parts of the program.

    Podcast Episode

    Listen to our 10-minute revision podcast covering all the core concepts, common exam mistakes, and a quick-fire recall quiz!

    Topic 6.2 Revision Podcast

    Visual Resources

    3 diagrams and illustrations

    The Three Core Constructs
    The Three Core Constructs
    Global vs Local Variable Scope
    Global vs Local Variable Scope
    Procedures vs Functions
    Procedures vs Functions

    Interactive Diagrams

    2 interactive diagrams to visualise key concepts

    Conceptual Flow Outline

    Start
    Input Age
    Input Age
    Is Age >= 18?
    Is Age >= 18?
    "Yes"Print 'Adult'
    "No"Print 'Minor'
    Print 'Adult'
    End
    Print 'Minor'
    End

    A flowchart demonstrating the Selection construct using a condition.

    Conceptual Flow Outline

    Start
    Set count = 0
    Set count = 0
    Is count < 5?
    Is count < 5?
    "Yes"Print 'Hello'
    "No"End
    Print 'Hello'
    count = count + 1
    count = count + 1
    Is count < 5?

    A flowchart demonstrating Condition-Controlled Iteration (a while loop).

    Worked Examples

    3 detailed examples with solutions and examiner commentary

    Practice Questions

    Test your understanding — click to reveal model answers

    Q1

    Identify the programming construct used in the following code: for i in range(10): print(i)

    1 marks
    foundation

    Hint: Look at the keyword 'for'. Does it make a decision, or does it repeat?

    Q2

    State two advantages of using subprograms in a large software project.

    2 marks
    standard

    Hint: Think about what happens if you find a bug, or if multiple people are working on the code.

    Q3

    A student has written a program with a variable total declared inside a function called calculate(). They try to print(total) in the main program, but get an error. Explain why.

    2 marks
    standard

    Hint: Think about the scope of the variable `total`.

    Q4

    Write a function called is_even that takes an integer as a parameter and returns True if the number is even, and False if it is odd.

    4 marks
    challenging

    Hint: You will need to use the modulo operator (MOD or %) to check for a remainder when divided by 2.

    Q5

    Explain the difference between count-controlled iteration and condition-controlled iteration, giving an example of when you would use each.

    4 marks
    challenging

    Hint: Compare 'for' loops with 'while' loops based on what you know *before* the loop starts.

    Key Terms

    Essential vocabulary to know