Algorithms that use sequence, branching and iteration together

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Algorithms that use sequence, branching and iteration together

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which part of an algorithm is a SEQUENCE?
A A step that repeats again and again
B Steps that happen one after another in order
2. Read this step: 'IF it is raining THEN take an umbrella'. What is it?
A A branch, because it makes a decision
B A loop, because it repeats
3. Read this step: 'REPEAT 5 times: bounce the ball'. What is it?
A A loop, because it repeats steps
B A branch, because it makes a choice
4. Which sentence is true about most algorithms?
A They can only use one of these at a time
B They often mix sequence, branches and loops
5. An algorithm says: 1. Get out your bag. 2. REPEAT UNTIL the bag is full: add a book. 3. Zip up the bag. Which part is the loop?
A Step 2, because it repeats until the bag is full
B Step 3, because it comes last

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
11. Get the bowl 2. Pour in the cereal AThis is a loop, not a branch. It repeats a step until a condition is true. It does not choose between paths.
2REPEAT 5 TIMES: Kick the ball BIF it is raining THEN take an umbrella ELSE wear a hat
3A branch is a decision that picks which steps to follow CSteps done in order ARE a sequence. Every algorithm has a sequence, even when it also has branches and loops.
4An algorithm can mix all three parts: a sequence, a branch and a loop DA sequence: steps done one after the other in order
5REPEAT UNTIL the bin is full: Put in a bottle (labelled as a branch) EA loop: a step that is repeated more than once
6Steps 1, 2 and 3 are all done in order, so this algorithm has no sequence F1. Open the gate 2. REPEAT 3 TIMES: IF dog is hungry THEN feed it

Definitions

sequence, branch, loop

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
walk to the door __ the door is shut THEN open the door
2.
______ 10 TIMES IF the cup is empty THEN fill the cup
3.
REPEAT UNTIL the bag is full IF the apple is ripe ____ pick the apple
4.
IF it is raining THEN take an umbrella ____ wear a cap
5.
Step 1: wake up // sequence REPEAT 3 TIMES // ____ IF tired THEN sleep // branch

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A SET claps TO 0
B IF 5 TIMES
C ADD 1 TO claps
D END REPEAT
E SHOW claps
Question 2
A ASK for the user's age
B IF age < 13 THEN
C SHOW 'You can join'
D ELSE
E SHOW 'You can join'
Question 3
A IF it is dark
B TURN ON the light
C ELSE
D TURN OFF the light
Question 4
A REPEAT 3 TIMES
B IF cup is full THEN
C FILL the cup
D END IF
E END REPEAT
Question 5
A FILL the kettle with water
B SWITCH ON the kettle
C SWITCH OFF the kettle
D POUR water into the cup

Answer Key

Algorithms that use sequence, branching and iteration together
Section A: Quick Questions
Q1
B — Steps that happen one after another in order
Q2
A — A branch, because it makes a decision
Q3
A — A loop, because it repeats steps
Q4
B — They often mix sequence, branches and loops
Q5
A — Step 2, because it repeats until the bag is full
Section B: Match the Pairs
Q1
1. Get the bowl 2. Pour in the cereal → A sequence: steps done one after the other in order
Q2
REPEAT 5 TIMES: Kick the ball → A loop: a step that is repeated more than once
Q3
A branch is a decision that picks which steps to follow → IF it is raining THEN take an umbrella ELSE wear a hat
Q4
An algorithm can mix all three parts: a sequence, a branch and a loop → 1. Open the gate 2. REPEAT 3 TIMES: IF dog is hungry THEN feed it
Q5
REPEAT UNTIL the bin is full: Put in a bottle (labelled as a branch) → This is a loop, not a branch. It repeats a step until a condition is true. It does not choose between paths.
Q6
Steps 1, 2 and 3 are all done in order, so this algorithm has no sequence → Steps done in order ARE a sequence. Every algorithm has a sequence, even when it also has branches and loops.
Section C: Definitions
Q1
sequence, branch, loop — Most algorithms mix steps in order (sequence), decisions (branch) and repeats (loop). When you read an algorithm, you can label each part and explain it in your own words.
Section D: Fill in the Blanks
Q1
walk to the door IF the door is shut THEN open the door
Q2
REPEAT 10 TIMES IF the cup is empty THEN fill the cup
Q3
REPEAT UNTIL the bag is full IF the apple is ripe THEN pick the apple
Q4
IF it is raining THEN take an umbrella ELSE wear a cap
Q5
Step 1: wake up // sequence REPEAT 3 TIMES // loop IF tired THEN sleep // branch
Section E: Spot the Error
Q1
B — The loop must start with REPEAT, not IF. IF is for a decision (branch). It should be REPEAT 5 TIMES so it matches END REPEAT.
Q2
C — This branch runs when the age is under 13, so it should show 'Ask a parent first'. 'You can join' belongs in the ELSE branch.
Q3
A — Every IF decision needs the word THEN after the condition. It should be IF it is dark THEN.
Q4
B — The branch should only fill the cup when it is empty. Filling a full cup makes no sense. It should be IF cup is empty THEN.
Q5
C — In a sequence the order matters. The kettle must stay on and the algorithm must wait until the water boils. The line should be WAIT UNTIL water boils.