Spotting sequence, branching and iteration in everyday systems

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

Spotting sequence, branching and iteration in everyday systems

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A traffic light goes red, then green, then yellow, then back to red, always in that order. Which building block is this?
A Sequence (steps in order)
B Branching (a decision)
2. A self-serve checkout says: IF the item is not on the scale, THEN ask the shopper to try again. Which building block is this?
A Branching (a decision)
B Iteration (a repeat)
3. An automatic door keeps checking for people, again and again, all day. Which building block does the checking again and again show?
A Iteration (a repeat)
B Sequence (steps in order)
4. An alarm app rings every 5 minutes until you press stop. Which part of the algorithm is the repeat?
A Press the stop button once
B Ring again every 5 minutes until stop is pressed
5. An automatic door: IF a person is standing in front of the sensor, THEN open the door. What is the condition?
A The door opens
B A person is standing in front of the sensor

Match the Pairs

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

Left columnRight column
1IF someone is at the door THEN open the door A1. Show green 2. Show yellow 3. Show red
2REPEAT UNTIL alarm is turned off: ring again BThe branch does the wrong action. When the light is red the cars should stop, not go.
3Sequence: a traffic light changes in the same order every time CBranching: the automatic door makes a decision and only opens when its condition is true
4Branching: a self-serve checkout takes a different action depending on what happens DIF item is scanned THEN beep ELSE show 'Try again'
51. Pay for items 2. Scan items 3. Pack bags EThe steps are in the wrong order. A checkout sequence must scan the items before the customer pays.
6Traffic light: IF the light is red THEN go FIteration: the alarm app repeats the same step over and over until a condition is met

Definitions

sequence, branching, iteration

Fill in the Blanks

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

1.
IF pedestrian button is pressed ____ turn the traffic light red
2.
IF person is near THEN open door ____ keep door shut
3.
1. Scan item _. Put item in bag 3. Pay for items
4.
REPEAT _______ change light to green change light to red
5.
REPEAT _____ snooze is pressed ring alarm

Spot the Error

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

Question 1
A Light turns green
B Light turns orange
C Light turns orange
D Wait 5 seconds
E Light turns red
Question 2
A Scan the item
B IF weight does not match THEN
C Print the receipt
D ELSE
E Add item to the bag
Question 3
A REPEAT FOREVER
B IF person is near THEN
C Open the door
D END IF
E Close the door
Question 4
A Set alarm for 7:00
B REPEAT 2 TIMES
C Play the alarm sound
D Wait 5 seconds
Question 5
A Check the crossing button
B IF button was pressed
C Light turns red for cars
D END IF

Answer Key

Spotting sequence, branching and iteration in everyday systems
Section A: Quick Questions
Q1
A — Sequence (steps in order)
Q2
A — Branching (a decision)
Q3
A — Iteration (a repeat)
Q4
B — Ring again every 5 minutes until stop is pressed
Q5
B — A person is standing in front of the sensor
Section B: Match the Pairs
Q1
IF someone is at the door THEN open the door → Branching: the automatic door makes a decision and only opens when its condition is true
Q2
REPEAT UNTIL alarm is turned off: ring again → Iteration: the alarm app repeats the same step over and over until a condition is met
Q3
Sequence: a traffic light changes in the same order every time → 1. Show green 2. Show yellow 3. Show red
Q4
Branching: a self-serve checkout takes a different action depending on what happens → IF item is scanned THEN beep ELSE show 'Try again'
Q5
1. Pay for items 2. Scan items 3. Pack bags → The steps are in the wrong order. A checkout sequence must scan the items before the customer pays.
Q6
Traffic light: IF the light is red THEN go → The branch does the wrong action. When the light is red the cars should stop, not go.
Section C: Definitions
Q1
sequence, branching, iteration — The three building blocks of algorithms: steps in order, decisions (IF) and repeats (loops). Traffic lights, self-serve checkouts, automatic doors and alarm apps all use them.
Section D: Fill in the Blanks
Q1
IF pedestrian button is pressed THEN turn the traffic light red
Q2
IF person is near THEN open door ELSE keep door shut
Q3
1. Scan item 2. Put item in bag 3. Pay for items
Q4
REPEAT FOREVER change light to green change light to red
Q5
REPEAT UNTIL snooze is pressed ring alarm
Section E: Spot the Error
Q1
B — A sequence must keep its steps in order. The light should wait 30 seconds on green before it turns orange. Line 2 should be 'Wait 30 seconds'.
Q2
C — This is the branch for when the weight does not match, so the checkout should call a staff member. Printing a receipt here is the wrong action. Line 3 should be ' Call a staff member'.
Q3
D — Ending the IF early removes the ELSE branch. The door would then close every time, even when a person is near. Line 4 should be ' ELSE'.
Q4
B — An alarm app should keep repeating until the user taps Stop. A fixed 2 repeats would end even if you are still asleep. Line 2 should be 'REPEAT UNTIL I tap Stop'.
Q5
B — An IF decision needs the word THEN after its condition. Line 2 should be 'IF button was pressed THEN'.