GCSE · Computer Science · Edexcel · Spec 1CP2
Sequence
Picture a quiz that cheers "Well done!" before it has asked you a single question. Nothing is missing. Every line the program needs is right there. So what's gone wrong?
Computer Science · Sequence
Same three lines, two orders
Run it one line at a time and keep your eye on the user column. It shows what the computer has stored so far.
Before you step into Order B: the welcome line wants to show user. Has anything been stored in user at that point?
1 # ORDER A: question, input, welcome2 print("What is your name?")3 user = input()4 print("Welcome", user)5 # ORDER B: the same three lines, welcome first6 print("Welcome", user)7 print("What is your name?")8 user = input()
| user |
|---|
| — |
Output
What is your name?
Step 1: Order A, line 1. The question pops up on the screen. Nothing is stored in user yet, and that's fine, because nothing needs it yet.
Press Next to run one line at a time. The computer runs exactly the lines it's given, in exactly the order it's given them.
Computer Science · Logic errors
Which sequence mistake is it?
Sort each snippet into the kind of sequence mistake it shows.
Still to sort
Displaying something before setting it (0)
The line that gives the value comes after the line that shows it.
Where the line is: The value is given directly by the program (like lives = 3). Nothing needs working out and nothing comes from the user.
Printing output before processing the data (0)
The line that works the answer out comes after the line that prints it.
Where the line is: The data is already there. The problem is that the working-out line sits below the print.
Asking for input after trying to use it (0)
The line that takes the input comes after the line that uses it.
Where the line is: The value is meant to come from the user, but the input line is too late.
Each snippet has one line in the wrong place. Pick a snippet, then pick the kind of mistake.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Same lines. Different order. Different result.
What you need to know
- Sequence is simply the order of the commands in a program.
- The computer runs a program from top to bottom, executing each line in turn, one statement at a time.
Have a goA seven-line program has just finished running line 4. Which line does it run next?
Line 5.
It works top to bottom, one line at a time, so the next line down is next. It doesn't jump ahead to whatever looks most important.
- With a run of print statements, the output appears in exactly the same order as the instructions.
Have a goYour mate writes print("Goal!") on line 1 and print("Kick-off") on line 2, then insists Kick-off shows first "because that's how football works". What really appears first?
Goal! appears first.
The output follows the order the lines are written. The computer knows nothing about football, only the order it was given.
- Computers do exactly what they're given, so a new order means new steps, and that can change the output.
- Having every line you need isn't enough if the lines are in the wrong order.
Have a goJo tidies your program by shuffling the lines around. "They're all still there," says Jo, "so it'll do the same thing." Is Jo safe to say that?
No. Jo can't promise that.
Keeping every line isn't the same as keeping the program: a new order means new steps for the computer, and the output can change.
- Wrong order gives unexpected or incorrect results. Runs fine, messages in the wrong order? That's a logic error.
- Three common sequence mistakes: displaying something before setting it, printing before processing the data, asking for input after using it.
- A welcome that shows user must come after the input is stored in user. Put it first and you get an error.
- Debugging means finding and fixing errors, and spotting a wrong sequence of instructions is a big part of it.
The big picture
A program runs its lines from top to bottom, one at a time, exactly as they are written. That makes the order part of the program: the right lines in the wrong order give unexpected or incorrect results, which is a logic error. Spotting a wrong sequence is a big part of debugging.
Key points
Worked example
Problem
A countdown program should show 3, then 2, then 1, then Lift off! on the screen, in that order. It has all four lines, but they're written as: print("Lift off!"), print(2), print(3), print(1). Put the lines in the right order.
⚠ Watch out
Thinking a program with every necessary line will work whatever order they're in. It's tempting, because nothing is missing. But the computer does exactly what it's told, in the order it's told, so a wrong order changes the steps it takes and can give the wrong output.
Memory hook
Top to bottom, exactly as told. The computer never reorders for you.
Check yourself
Line 1 is print(score); line 2 is score = 10. Which sequence mistake is this, and what's the fix? Answer: displaying something before setting it. Swap the lines.
Flashcards
(12)What is sequence in a program?
In what order does a program run its lines?
In a program of print statements, how is the output ordered?
Why can changing the order of lines change the output?
Every line is present, but the program misbehaves. What's the likely culprit?
What do instructions in the wrong order produce?
A program runs to the end but its messages come out in the wrong order. What kind of error is that, and what's the fix?
Name the three common sequence mistakes.
Why must a welcome message that shows user come after the input?
What is the correct sequence for the welcome program?
What is debugging?
What two things can errors do to a program?
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 Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson 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 26 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.