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 = 3
2 crisps_price = 2
3 drink_price = 4
4 print("Chocolate:", chocolate_price)
5 print("Crisps:", crisps_price)
6 print("Drink:", drink_price)
7 print("Enter your choice")
8 choice = input()
chocolate_pricecrisps_pricedrink_pricechoice
3

Output

 

Step 1: First line, so it runs first. chocolate_price now holds 3 (coins). The other two prices don't exist yet.

1 / 8

Step through the trace — every value is the lesson’s, not run by the page.

Step 1 of 8: First line, so it runs first. chocolate_price now holds 3 (coins). The other two prices don't exist yet..

Watch out: A blank cell means that variable has no value yet, because the line that gives it one hasn't run. The prices only exist once their lines have run.

Computer Science · Sequence

So how does a computer run your lines?

Someone writes an ATM program with the lines in a muddle: the line that checks the PIN is written above the line that asks for the PIN.

Which is closest to what you think the computer does with those lines?
How sure are you?

Computer Science · Sequence

Your turn: fix the ATM program

the order the ATM program must run its steps in

1 · Runs first4 · Runs last
  1. Check the PIN

  2. Output "Access Granted" if the PIN is correct, or "Access Denied" if it is wrong

  3. Welcome the user

  4. Ask the user to enter the PIN

Watch out: Ask yourself what each step needs to have happened already.

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?

TrueFalseStartWelcome theuserAsk the userto enter thePINIs the PINcorrect?Output "AccessGranted"Output "AccessDenied"End

Output

 

Step 1: In we go.

1 / 6

Step through the trace — every value is the lesson’s, not run by the page.

Step 1 of 6: In we go..

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.

6 of 6 still to sort.

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

1Sequence: instructions run in the order they appear in the code, one after another.
2The computer doesn't rearrange a muddled program. The written order is the running order.
3Selection: more than one path, chosen by a True or False condition (for example an if statement).
4Iteration (looping): the same lines of code run more than once (for example a while loop).
5Flow charts: sequence is symbols running one after another; selection is a decision symbol with True and False coming off it.
6Sequence, selection and iteration can be combined to create more complex programs.

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.
Sequence, selection and iteration.
What is sequence?
The order of commands in a program: instructions run in the order they appear in the code, one after another.
Your lines are in the wrong order. What does the computer do?
Runs them in the wrong order. It doesn't sort them out; the programmer has to.
How does a flow chart show sequence?
A number of symbols running one after another.
How does a flow chart show selection?
A decision symbol with True and False coming off it.
When is selection used?
When there is more than one path for a program to follow; code runs based on whether a condition is True or False.
Give an example of selection in code.
An if statement.
What is another name for iteration?
Looping.
What does iteration let you do? Give an example.
Run the same lines of code more than once, for example with a while loop.
ATM program: what happens straight after the user is welcomed?
The user is asked to enter the PIN.
Vending machine program: what happens just before the input is stored in choice?
The program prints "Enter your choice" (after showing the prices).
Why combine sequence, selection and iteration?
Combining them lets you create more complex programs.

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 posted

More KS3 Computer Science topics

See the full KS3 Computer Science curriculum →

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.

Helpful guides for parents and students