KS3 · Computer Science
Sequencing instructions in Scratch
A cash machine that checks your PIN before you've typed it? A computer would do exactly that if its lines were written in that order.
Computer Science · Programming
A vending machine program, one line at a time
Press next and watch each line run. Nothing happens until the line above it has finished.
Before you press next: drink_price = 4 has just run. Which line runs straight after it?
1 chocolate_price = 32 crisps_price = 23 drink_price = 44 print("Chocolate:", chocolate_price)5 print("Crisps:", crisps_price)6 print("Drink:", drink_price)7 print("Enter your choice")8 choice = input()
| chocolate_price | crisps_price | drink_price | choice |
|---|---|---|---|
| 3 |
Output
Step 1: First line, so it runs first. chocolate_price now holds 3 (coins). The other two prices don't exist yet.
Step through the trace — every value is the lesson’s, not run by the page.
Computer Science · Flow charts
Same ATM, drawn as a flow chart
Follow the arrows when the PIN typed in is wrong. Notice where the chart runs straight and where it splits.
The PIN typed in is wrong. Which arrow out of the decision symbol will the program follow, True or False?
Output
Step 1: In we go.
Step through the trace — every value is the lesson’s, not run by the page.
Computer Science · Control structures
Sequence, selection or iteration?
Which control structure does each one show?
Still to sort
Sequence (0)
Instructions run in the order they appear, one after another.
Where the line is: No choice and no repeat: just the next line, then the next.
Selection (0)
More than one path; which code runs depends on a condition being True or False.
Where the line is: Selection picks a path. It doesn't run the same lines again; that's iteration.
Iteration (0)
Also called looping: the same lines of code run more than once.
Where the line is: Iteration goes round again. Sequence just moves on to the next line.
These are the three main control structures. Decide which one each description shows, in code and in flow charts.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
No guessing, no reshuffling. Line one, then line two, then line three.
What you need to know
- There are three main programming control structures: sequence, selection and iteration.
- Sequence is the order of commands in a program.
- The computer runs instructions in the order they appear in the code, one after another.
- It never tidies up a muddled order for you. Getting the lines in the right order is the programmer's job.
Have a goRobo-chef's recipe program reads: 1. eat the cake 2. bake the cake 3. mix the ingredients. Robo-chef follows programs exactly. What does it try to do first?
Eat the cake, which doesn't exist yet.
Line 1 runs first simply because it appears first. Robo-chef won't reshuffle it into the sensible order; the programmer has to.
- A variable only has its value once the line that sets it has run.
- On a flow chart, sequence looks like a number of symbols running one after another.
- Selection is for when a program has more than one path: code runs depending on whether a condition is True or False.
- An if statement is an example of selection; in a flow chart it's a decision symbol with True and False coming off it.
Have a goAn ATM program welcomes the user, asks for the PIN, checks the PIN, then outputs "Access Granted" or "Access Denied". Drawn as a flow chart, which step becomes the decision symbol?
Checking the PIN.
It's the only step with two ways out, True or False. The other steps just follow one another, which is sequence.
- Iteration, also known as looping, lets you run the same lines of code more than once, like a while loop does.
Have a goA game keeps running the same few lines while the player says yes to "Play again?". Sequence, selection or iteration?
Iteration (looping).
There's a condition in there, which might make you think selection, but the giveaway is that the same lines run more than once.
- Combine sequence, selection and iteration and you can build much more complex programs.
The big picture
Sequence is the order of commands in a program: the computer runs instructions in the order they appear in the code, one after another, and it never rearranges them into a more sensible order. You'll watch a vending machine program run line by line, put an ATM program's steps in order, and see sequence and selection drawn in a flow chart. Sequence is one of the three main control structures, alongside selection (more than one path, chosen by a True or False condition) and iteration (running the same lines more than once). Combine all three and you can build much more complex programs.
Key points
Worked example
Problem
Trace this program. What does it print, and in what order? score = 5 print(score) score = 8 print(score)
⚠ Watch out
Assuming the computer will sort a muddled program into the order you meant. It won't. It runs the lines exactly as they appear, so an ATM program with the PIN check written first checks the PIN before anyone has typed one.
Memory hook
Line one, then line two, then line three: the computer is a very fast, very literal reader that never skips ahead and never tidies up.
Check yourself
Without scrolling up: say in your own words what sequence means, then explain why, in the ATM program, asking for the PIN has to come before checking it.
Flashcards
(12)Name the three main programming control structures.
What is sequence?
Your lines are in the wrong order. What does the computer do?
How does a flow chart show sequence?
How does a flow chart show selection?
When is selection used?
Give an example of selection in code.
What is another name for iteration?
What does iteration let you do? Give an example.
ATM program: what happens straight after the user is welcomed?
Vending machine program: what happens just before the input is stored in choice?
Why combine sequence, selection and iteration?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore KS3 Computer Science topics
How this lesson was checked. This KS3 Computer Sciencelesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 27 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.