What are the structural components of a program, and how do you use sequence, selection, repetition and iteration in Python?
Identify the structural components of programs (constants, variables, initialisation, assignment, sequence, selection, repetition, iteration, data structures, subprograms, parameters, input/output) and write programs that use sequencing, selection, repetition (count-controlled, condition-controlled) and iteration with single entry and exit points.
A focused answer to Edexcel GCSE Computer Science 6.2, covering the structural components of programs and writing Python programs that use sequence, selection, count-controlled and condition-controlled repetition, and iteration.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
Edexcel wants you to identify the structural components of a program and to write Python programs that use sequence, selection, repetition (count-controlled and condition-controlled) and iteration, with single entry and exit points from code blocks.
The structural components of a program
These are the named parts a question may ask you to point out in a piece of code. For example, in a program, the line total = 0 is initialisation (and assignment) of a variable; an if is selection; a for is repetition; input() and print() are input/output; and a defined function is a subprogram. Knowing the vocabulary lets you answer "identify the selection statement" or "name the component on line 3".
Sequence
name = input("Name: ")
print("Hello " + name)
These two lines run in sequence: read the name, then greet.
Selection
if mark >= 40:
print("pass")
else:
print("fail")
For several cases, chain with elif (as in the positive/negative/zero example), which is cleaner and more efficient than separate if statements because once a branch matches the rest are skipped.
Repetition and iteration
# Count-controlled: known number of repeats
for i in range(1, 6):
print(i)
# Condition-controlled: repeat until the user types "quit"
command = ""
while command != "quit":
command = input("Command: ")
# Iteration over every item in a list
for score in scores:
print(score)
The choice is the same logic as in algorithms: a for/range loop when the count is known, a while loop when it depends on a condition, and a for ... in loop to process each element of a structure.
Single entry and exit points
Writing structured code, where each loop and subprogram has one way in and one way out, keeps the flow predictable. It is part of structured programming and is why GCSE algorithms avoid unstructured jumps: a reader can follow the logic top to bottom without tracking jumps into the middle of a block.
Try this
Q1. State which Python construct repeats a known number of times. [1 mark]
- Cue. A
forloop (over arange), which is count-controlled repetition.
Q2. Write a Python if statement that prints "big" when a variable n is greater than 100. [2 marks]
- Cue.
if n > 100:then on the next indented lineprint("big").
Exam-style practice questions
Practice questions written in the style of Pearson Edexcel exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
Edexcel 20225 marksWrite a Python program that asks the user for a whole number and prints whether it is positive, negative or zero.Show worked answer →
A correct solution reads the input, converts it to an integer, then uses selection with elif.
number = int(input("Enter a whole number: "))
if number > 0:
print("positive")
elif number < 0:
print("negative")
else:
print("zero")
Markers reward reading the input and converting it with int(), correct use of if/elif/else covering all three cases (positive, negative, zero), correct comparisons, and matching output. Using a single chain (if/elif/else) is cleaner than three separate ifs.
Edexcel 20215 marksWrite a Python program that uses a count-controlled loop to print the squares of the numbers 1 to 5 (that is 1, 4, 9, 16, 25).Show worked answer →
Use a for loop over range(1, 6), printing each number multiplied by itself (or to the power 2).
for i in range(1, 6):
print(i * i)
This is count-controlled (definite) iteration because the number of repetitions (5) is known. The output is 1, 4, 9, 16, 25.
Markers reward a correct loop range that gives 1 to 5, computing the square (i * i or i ** 2), printing inside the loop, and producing the five correct values. Using range(1, 5) would be an off-by-one error.
Related dot points
- Use decomposition and abstraction to solve problems; read, write, analyse and refine programs; convert algorithms (flowcharts, pseudocode) into programs; use techniques (layout, indentation, comments, meaningful identifiers, white space) for readable code; identify, locate and correct logic, syntax and runtime errors; and evaluate a program's fitness for purpose and efficiency.
A focused answer to Edexcel GCSE Computer Science 6.1, covering using decomposition and abstraction in programs, converting algorithms to code, writing readable code, identifying and correcting errors, and evaluating fitness for purpose.
- Write programs that make appropriate use of primitive data types (integer, real, Boolean, char) and one- and two-dimensional structured data types (string, array, record), and that make appropriate use of variables and constants.
A focused answer to Edexcel GCSE Computer Science 6.3.1 and 6.3.2, covering the primitive data types (integer, real, Boolean, char), structured types (string, array, record) in one and two dimensions, and using variables and constants.
- Follow and write algorithms that use arithmetic operators (addition, subtraction, division, multiplication, modulus, integer division, exponentiation), relational operators (equal to, less than, greater than, not equal to, less than or equal to, greater than or equal to) and logical operators (AND, OR, NOT).
A focused answer to Edexcel GCSE Computer Science 1.2.3, covering the arithmetic operators including modulus and integer division, the relational operators, and the logical operators AND, OR and NOT in algorithms.
- Write programs that use pre-existing and user-devised subprograms (procedures, functions), write functions that return values and procedures that do not, with or without parameters, use the arithmetic, relational and logical operators, and use global and local variables appropriately.
A focused answer to Edexcel GCSE Computer Science 6.5 and 6.6, covering functions and procedures, parameters and return values, built-in and user-defined subprograms, the operators, and global versus local variables in Python.
- Write programs that accept and respond appropriately to user input, and that read from and write to comma separated value text files.
A focused answer to Edexcel GCSE Computer Science 6.4.1 and 6.4.2, covering accepting and responding to user input, and reading from and writing to comma separated value (CSV) text files in Python.
Sources & how we know this
- Pearson Edexcel GCSE (9-1) Computer Science (1CP2) specification — Pearson (2020)
- Pearson Edexcel GCSE Computer Science Programming Language Subset (Python) — Pearson (2020)