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, welcome
2 print("What is your name?")
3 user = input()
4 print("Welcome", user)
5 # ORDER B: the same three lines, welcome first
6 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.

1 / 4

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.

Step 1 of 4: 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..

Watch out: Check the code panel. Order B uses exactly the same three lines as Order A. Nothing added, nothing removed. Only the order moved.

Computer Science · Sequence

Shuffled game: put the lines back in order

the order the computer should run the print lines so the game makes sense

1 · Runs first4 · Runs last
  1. print("Level completed")

    Tells the player they've finished the level.

  2. print("Score saved")

    Reports that the result has been stored.

  3. print("Get ready")

    Warns the player the game is about to begin.

  4. print("Level 1 starts!")

    Announces the start of play.

Watch out: Commit to your order before you check. Ask of each line: should the player see this first, second, third or last?

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.

6 of 6 still to sort.

Each snippet has one line in the wrong place. Pick a snippet, then pick the kind of mistake.

Watch out: Ask where the missing value was meant to come from: a line that gives it directly, a line that works it out, or the user.

Computer Science · Debugging

Find the line in the wrong place

This program should add up two prices and then print the total. Every line is there, but one is in the wrong place. Which one?

A student's program — which line goes wrong?

Computer Science · Common misconceptions

All the lines are there. So it works, right?

A programmer has written every line a program needs, but the lines are in a muddled order.

Which idea is closest to what you think will happen?
How sure are you?

Computer Science · Exam practice

Explain it in your own words

Explain how the sequence of a program affects the output it produces. You may use an example. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

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

1Sequence is the order of the commands, and a program runs them top to bottom, one line at a time.
2The computer executes instructions exactly as given, so changing the order changes the steps, and that can change the output.
3A wrong order gives unexpected or incorrect results. If the program runs but its messages are in the wrong order, it has a logic error.
4The fix for a sequence logic error is to put the instructions in the correct order.
5Debugging is finding and fixing errors. Errors can stop a program running or make it give the wrong output.

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?
The order of the commands in the program.
In what order does a program run its lines?
From top to bottom, executing each line in turn, one statement at a time.
In a program of print statements, how is the output ordered?
In the same order as the print instructions are written in the program.
Why can changing the order of lines change the output?
Computers execute instructions exactly as given, so a new order means different steps for the computer, and different steps can give a different output.
Every line is present, but the program misbehaves. What's the likely culprit?
The lines are in the wrong order. Having all the necessary lines isn't enough.
What do instructions in the wrong order produce?
Unexpected or incorrect results.
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?
A logic error. Fix it by putting the instructions in the correct order.
Name the three common sequence mistakes.
Displaying something before setting it, printing output before processing the data, and asking for user input after trying to use it.
Why must a welcome message that shows user come after the input?
user only holds a value once the input has been taken and stored. Printing the welcome first results in an error.
What is the correct sequence for the welcome program?
Print 'What is your name?', take the input and store it in user, then print the welcome message.
What is debugging?
Finding and fixing errors in a program.
What two things can errors do to a program?
Stop it from running, or make it produce the wrong output.

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 Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.