- Home
- Lessons
- GCSE & IGCSE Computer Science
- Sequence, selection and iteration
Sequence, selection and iteration
🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.
If you used Scratch or Python at KS3, you have already used the three building blocks of every program. At GCSE you write and read them in Python.
Sequence
Sequence means instructions run one after another, in order.
Change the order and you can change the result.
price = 4
qty = 3
total = price * qty
print(total)
Output: 12
Change the order and you can change the result.
price = 4
qty = 3
total = price * qty
print(total)
Output: 12
Selection
Selection means a decision chooses which instructions run. In Python this is if and else.
The lines that belong to the if are indented.
temp = 24
if temp > 20:
print("Shorts")
else:
print("Jeans")
Output: Shorts
The lines that belong to the if are indented.
temp = 24
if temp > 20:
print("Shorts")
else:
print("Jeans")
Output: Shorts
Iteration
Iteration means repeating instructions using a loop.
A for loop repeats a set number of times. A while loop repeats while a condition is True.
for i in range(3):
print("Hip hip hooray")
The message is printed 3 times. range(3) gives 0, 1, 2.
A for loop repeats a set number of times. A while loop repeats while a condition is True.
for i in range(3):
print("Hip hip hooray")
The message is printed 3 times. range(3) gives 0, 1, 2.
What does this program print?
total = 0
for n in range(1, 6):
total = total + n
print(total)
- range(1, 6) gives 1, 2, 3, 4, 5 (it stops before 6).
- total goes 1, 3, 6, 10, 15.
Answer: 15
Sequence: steps in order. Selection: if/else chooses a path. Iteration: for repeats a set number of times; while repeats while a condition is True. Indentation shows which lines belong inside.
Check you have got it
Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.