top of page

Programming constructs: sequence, iteration, branching. (2.2.1)

  • 20p13280
  • Oct 13, 2025
  • 3 min read

Updated: Oct 21, 2025

This post covers the following from the specification (2.2.1):

(a) Programming constructs: sequence, iteration, branching.

(b) Recursion, how it can be used and compares to an iterative approach.

(c) Global and local variables.

(d) Modularity, functions and procedures, parameter passing by value and by reference.

(e) Use of an IDE to develop/debug a program.

(f) Use of object oriented techniques. (Skipped for now)


Sequencing

Sequencing is the order of which instructions are executed. Sequencing is a vital part of writing programs as code needs to be executed in the order it was written in to work properlly. For example if you declared a variable then printed it but it was executed the other way around it wouldn't work as the variable wouldn't be defined yet.


Here's an example of sequencing:

first = "First Message"
third = "Third Message"
print(first)
print("Second Message")
print(third)

This program initialises 2 variables, first and third, and then prints them out and inbetween those 2 print statements there is one more to print out "Second Message".

The expected output of the program would be:

First Message
Second Message
Third Message

This is outputted in the same order as it's written because of sequencing.


Selection

Selection is where the program can run a different optional branche of code based on a condition within the program. This is useful for programmers as it allows their program output to adapt based on user output and events.


Here is an example of selection:

import random
number = random.randint(1,5)
guess = int(input("Guess the number (1-5): "))
if number == guess:
    print("You guessed it!")
elif guess > number:
    print("Too high")
else:
    print("Too low")

In this example there are three "branches". They are run based on the users guess being compare to the random number. So if the number generated was 2 and the user inputs 2, it will output "You guessed it!", if the user inputs 1 it will output "Too low" and if the user inputs 3+ it wil output "Too high". This


Iteration

Iteration is where code is run over and over in a loop so that a programmer doesn't have to keep re-writing the same code again and again. This saves time for the programmer and also allows for better programms to be written that are more readable and maintainable. An example of this making code more maintainable and readable is using a for loop to print out "Hello, World" 100 times instead of writing the print line manually 100 times.


Here's an example of Iteration:

for i in range(0,100): # Count controlled controlled
    print(i+1)

num = 6
while num > 5: # Conditiion controlled loop
    print("Number is greater than 5")
    num = int(input("Enter a new number: "))

import time, datetime

while True: # Infinate loop
    current_time = datetime.now()
    print("Here is the current time: ")
    print(current_time)
    time.sleep(3)

The first loop is a count controlled controlled loop, this means that it will run the amount of times specified within the loop. In this case the loop is using range(0,100) so, as this is python, it will run 100 times with the variable i starting at 0 and ending at 99.


The second loop is a condition controlled loop, this means that it will only run the code within the block if the condition specified after the "while" is true. Once it's false the code will no longer run and the loop will exit.


The third loop is an infinate loop, it uses the same while keyword as in the prior loop but this time it always makes the condition true by setting the condition to check as true itself. This loop will run infinately whilst the program is running.

 
 
 

Recent Posts

See All
Data Structures - Linked Lists (1.4.2)

This post covers the following topics: Linked Lists Linked Lists Linked lists are the most common type of dynamic data structure, as they are dynamic they can grow to any size that is required. Their

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
Project Volt Logo
bottom of page