Structural components of programs (Edexcel GCSE Computer Science): Revision Notes
Structural components of programmes
What are structural components?
When you're learning to programme, it's essential to understand how programmes are built from different structural components. Think of these as the building blocks that make up any computer programme - just like how a house is made from bricks, windows, doors, and other parts.
These components work together to create algorithms that can solve problems and perform tasks. Understanding them helps you read, write, and debug programmes more effectively.
Learning these structural components is like learning the vocabulary of programming - once you know them, you can understand and communicate about any programme!
The main structural components you need to know
Constants
Constants are fixed values that never change during programme execution. You can spot them because they're usually written in ALL_UPPERCASE letters.
MAX_OCCUPANCY = 6
In this example, MAX_OCCUPANCY is a constant representing the maximum number of people allowed. Once set, this value stays the same throughout the entire programme.
Variables
Variables are like storage boxes with names that can hold different values. Unlike constants, the values inside variables can change as your programme runs.
numPeople = 0
Here, numPeople is a variable that starts with the value 0, but it can be updated later.
Declaration and initialisation
Declaration is when you create a variable and specify what type of data it will hold. Initialisation is when you give that variable its first value.
numPeople = int() # Declaration - creates an integer variable
numPeople = 0 # Initialisation - gives it a starting value
Many programming errors come from using variables before they've been properly declared and initialised. Always make sure your variables have starting values!
Assignment statements
Assignment is the process of giving a value to a variable using the equals sign (=). The equals sign doesn't mean "equal to" like in maths - it means store this value in this variable.
numPeople = int(input("Enter number: "))
This line takes user input, converts it to an integer, and stores it in the numPeople variable.
Selection structures
Selection allows your programme to make decisions using if, elif, and else statements. The programme chooses which code to run based on certain conditions.
if (numPeople < 1):
print("Invalid number")
elif (numPeople > MAX_OCCUPANCY):
print("Too many people")
else:
print("Number of people will fit.")
This selection structure checks the number of people and displays different messages depending on the value.
Repetition and iteration
Repetition (also called iteration) lets your programme repeat actions using loops like for loops or while loops.
for numSides in range(4):
tim.forwards(sideLength)
tim.left(90)
This for loop repeats the same actions 4 times to draw a square.
Input and output functions
Input functions get data from the user, while output functions display information back to them.
- input() - gets text from the keyboard
- print() - displays information on the screen
Command sequences
A command sequence is simply a series of instructions that run one after another in order. Most of your programme code consists of command sequences.
Parameters
Parameters are values that get passed into functions or subprograms to customise how they work.
tim.forwards(sideLength) # sideLength is a parameter
Identifying components in practice
Worked Example: Identifying Structural Components
Let's look at a real code example and identify the structural components:
import turtle
sideLength = 0
tim = turtle.Turtle()
sideLength = int(input("Length: "))
tim.pencolor("BlueViolet")
for numSides in range(4):
tim.forwards(sideLength)
tim.left(90)
Can you spot:
- Variable: sideLength (stores the square's side length)
- Assignment: sideLength = int(input("Length: "))
- Sequence of commands: Lines 9-11 that draw each side
- Repetition: The for loop that runs 4 times
- Parameter: sideLength passed to tim.forwards()
Exam tips
Essential Exam Tips:
- Constants are UPPERCASE: Look for variables written in capital letters
- Selection spans multiple lines: if/elif/else structures often cover several lines of code
- Look for the = sign: This usually indicates assignment
- Count loop iterations: For loops often show how many times something repeats
- Input/output functions: input() gets data in, print() shows data out
Common exam question types
What You Might Be Asked:
You might be asked to:
- Identify different structural components in given code
- Give line numbers where specific components appear
- Explain what each component does
- Name variables, constants, or parameters from code examples
Remember!
Key Points to Remember:
- Structural components are the building blocks that make up all computer programmes
- Constants never change, while variables can store different values
- Selection structures help programmes make decisions using if/elif/else
- Loops create repetition by running the same code multiple times
- Assignment uses the = operator to store values in variables