Skip to content
Definition
Programming constructs are the building blocks used to control the flow of a program. In structured programming, three main constructs are employed: sequence, branching (selection), and iteration.

The Three Basic Constructs

Key Point
ConstructPurposeTypical syntax
SequenceExecute statements in fixed orderStraight line code
Branching (selection)Choose path based on conditionIF / ELSEIF / CASE
IterationRepeat a block multiple timesFOR / WHILE / REPEAT UNTIL
Worked Example
Programming Constructs Examples
ConstructExample behaviour
SequenceRead name/age, then print messages in order
BranchingIF age-based message OR CASE day-name mapping
IterationFOR counter loop, WHILE password check, REPEAT-UNTIL guessing loop
pseudocode
// Sequence
name = input("Enter name: ")
age = input("Enter age: ")
print("Hello " + name)
print("You are " + age + " years old")

// Branching
if age >= 18 then
    print("You can vote")
elseif age >= 16 then
    print("You can drive")
else
    print("You are too young")
end if

switch day:
    case 1: print("Monday")
    case 2: print("Tuesday")
    case 3: print("Wednesday")
    default: print("Other day")
end switch

// Iteration
for i = 1 to 10:
    print(i)
end for

while password != "secret" do
    password = input("Enter password: ")
end while

repeat
    guess = input("Guess the number: ")
until guess == targetNumber

Count-Controlled and Condition-Controlled Iteration

LoopType of iterationWhen the condition is testedFewest times the code inside runs
forCount-controlledNo condition: it repeats a set number of timesFixed by the start and end values
whileCondition-controlled, pre-conditionBefore each pass0
do-until (also written repeat-until)Condition-controlled, post-conditionAfter each pass1
Exam Tip
A while loop tests its condition at the start, so the code inside may never run. A do-until loop tests its condition at the end, so the code inside always runs at least once. A while loop repeats while its condition is true; a do-until loop repeats until its condition becomes true.