🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year
🐍 Paper 2 · Topic 6: Programming
6.1b Sequence, Selection & Iteration
Edexcel 1CP2 · GCSE Computer Science · ~14 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

The Three Programming Constructs

All programs — no matter how complex — are built from just three fundamental constructs: sequence, selection, and iteration.

1. Sequence

Sequence means instructions are executed one after another, in order, from top to bottom. This is the default in Python.

# Sequence example name = input("Name: ") age = int(input("Age: ")) year_of_birth = 2025 - age print(name + " was born in " + str(year_of_birth))

2. Selection (if/elif/else)

Selection allows the program to make decisions and execute different code depending on a condition. Python uses if, elif (else if), and else.

# Selection: if / elif / else score = int(input("Enter score: ")) if score >= 70: print("Grade: A") elif score >= 60: print("Grade: B") elif score >= 50: print("Grade: C") else: print("Grade: F")

Key rules for selection:

  • Conditions use comparison operators: ==, !=, >, <, >=, <=
  • Indentation (4 spaces or 1 tab) is mandatory in Python — it defines the block
  • elif is optional and can be repeated; else is optional and covers all remaining cases

3. Iteration (loops)

Iteration allows code to repeat. Python has two types of loop:

for loop — count-controlled iteration

Used when you know exactly how many times to repeat:

# for loop — repeats a fixed number of times for i in range(5): # i = 0, 1, 2, 3, 4 print("Count:", i) # range(start, stop, step) for i in range(1, 11): # 1 to 10 (not 11) print(i) for i in range(0, 10, 2): # 0, 2, 4, 6, 8 print(i)

while loop — condition-controlled iteration

Used when you don't know how many times to repeat — loop continues as long as a condition is True:

# while loop — repeats while condition is True password = "" while password != "secret123": password = input("Enter password: ") print("Access granted!")

Comparison: for vs while

for loopwhile loop
Count-controlled (fixed number of iterations)Condition-controlled (unknown iterations)
Uses range() or iterates over a collectionContinues while condition is True
Loop variable managed automaticallyMust manually manage the condition variable
Example: repeat 10 timesExample: keep asking until valid input

Nested Structures

You can put loops inside loops, and if statements inside loops:

# Nested loop example — multiplication table for i in range(1, 4): for j in range(1, 4): print(i * j, end=" ") print() # Selection inside a loop for i in range(1, 11): if i % 2 == 0: print(i, "is even") else: print(i, "is odd")
Exam tip: The Edexcel paper 2 is a practical Python exam on computer. You'll need to write working code. Practice tracing through loops mentally — know what each iteration does. Common exam tasks: count values in a list, find maximum, validate user input using while.
⚠️ Common Mistakes
  • Missing the colon after if/elif/else/for/while — causes SyntaxError
  • Wrong indentation — Python uses indentation to define blocks; inconsistent indentation causes IndentationError
  • Using = (assignment) instead of == (comparison) in an if condition
  • range(10) gives 0–9 (not 1–10); range(1, 11) gives 1–10
  • Infinite while loop — forgetting to update the condition variable inside the loop
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — 6.1b Sequence, Selection & Iteration

8 Edexcel-style questions · instantly marked

Q1Name the three fundamental programming constructs and briefly describe each.[6]
✅ Mark scheme
Sequence: instructions executed one after another, in order [1]; Selection: a decision/condition that determines which code block executes [1]; Iteration: code that repeats (loops) [1]. 1 mark each for correct name, 1 mark each for correct description. Max 6.
Q2Write Python code using a while loop that keeps asking the user to enter a number between 1 and 10 until they do so. When valid, print "Valid input!"[4]
✅ Mark scheme
num = int(input("Enter a number 1-10: ")) [1]; while num < 1 or num > 10: [1]; (indented) num = int(input("Enter a number 1-10: ")) [1]; print("Valid input!") [1].
Q3Trace through this code and state what is printed: for i in range(2, 10, 3): print(i)[2]
✅ Mark scheme
Prints: 2 [1]; 5 [1]; 8 [1] — range(2, 10, 3) generates 2, 5, 8 (stops before 10). [Award 2 marks for all three correct, 1 mark for two correct.]
Q4A student writes this code. Identify ALL errors: if score > 50 print("Pass") else print("Fail")[2]
✅ Mark scheme
Missing colon after condition (should be if score > 50:) [1]; missing colon after else (should be else:) [1]; also missing indentation on both print statements (accept this as a third error).
Q5Explain when you would use a for loop rather than a while loop.[2]
✅ Mark scheme
Use a for loop when the number of iterations is known in advance/fixed [1]; e.g. counting from 1 to 10, or processing each item in a list. Use a while loop when the number of iterations depends on a condition that may change at runtime [1].
Q6Write Python code to print all even numbers from 0 to 20 using a for loop and selection (if statement).[3]
✅ Mark scheme
for i in range(0, 21): [1] (accept range(21) or range(0,22,2) — give full marks for range(0,22,2) without if statement); if i % 2 == 0: [1]; print(i) [1]. (Alt: for i in range(0, 21, 2): print(i) — award 3 marks.)
Q7What is an infinite loop? Give an example of code that would cause one and explain how to fix it.[3]
✅ Mark scheme
A loop that never terminates because its exit condition is never met [1]; Example: count = 1; while count > 0: print(count) — count stays positive forever [1]; Fix: update the condition variable inside the loop so it eventually becomes False, e.g. count -= 1 [1].
Q8Write a Python program that asks a user to enter 5 numbers one at a time, then prints the largest number entered.[5]
✅ Mark scheme
largest = None (or ask first number before loop) [1]; for i in range(5): [1]; num = int(input("Enter number: ")) [1]; if largest is None or num > largest: [1]; largest = num [1]; print("Largest:", largest) — awarded even if outside loop [1]. Max 5.
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Sequence, Selection & Iteration

Timed exam-style test — 10 minutes.

← 6.1a Variables & Data TypesTopic 6 · PythonNext: 6.1c Subroutines →