GCSE · Computer Science · Edexcel · Spec 1CP2

Sequence

Picture a quiz that says "Well done!" before it has asked you a single question. Nothing is missing. Every line the program needs is there. So what went wrong?

Computer Science · Sequence

Same three lines, two orders

Step through the program one line at a time. Watch the user column: it tells you what the computer has stored so far.

Before you step through Order B: the welcome line wants to show user. Has anything been stored in user yet?

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 appears on the screen. Nothing is stored in user yet, and that is fine, because nothing needs it yet.

1 / 4

Press Next to run one line at a time. The lines that run are the ones the computer is told to run, in the order it is told to run them.

Step 1 of 4: Order A, line 1. The question appears on the screen. Nothing is stored in user yet, and that is fine, because nothing needs it yet..

Watch out: Look at the code panel. Order B has exactly the same three lines as Order A. Nothing was added or removed.

Computer Science · Sequence

Shuffled game: put the lines 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 have 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: Decide the order first, then check it. The point is to reason about which line the computer should run first, second and so on.

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.

Printing output before processing the data (0)

The line that works the answer out comes after the line that prints it.

Asking for input after trying to use it (0)

The line that takes the input comes after the line that uses it.

6 of 6 still to sort.

Each snippet has exactly one thing wrong. Pick a snippet, then pick the kind of mistake.

Watch out: Ask yourself which line comes too late: the one that sets a value, the one that works it out, or the one that asks the user.

Computer Science · Debugging

Find the line that is in the wrong place

This program should work out the total of two prices and then print it. The lines are all there, but one line 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 the order of the commands in a program.
  • A program runs from top to bottom, executing each line in turn, one statement at a time.
  • Have a goA program has five lines. The computer has just finished line 2. What does it do next?

    It runs line 3.

    The program runs from top to bottom, one line at a time, so the next line down is the next to run.

  • In a program of print statements, the output appears in the same order as the instructions.
  • Computers execute instructions exactly as given, so a different order means different steps and different output.
  • Have a goJo says: "I tidied your program by shuffling the lines around. They are all still there, so it will do the same thing." Will it?

    Not safely. Changing the order changes the steps, so the output changes.

    The computer does exactly what it is given in the order it is given, so keeping every line is not the same as keeping the program.

  • Having all the necessary lines is not enough if they are in the wrong order.
  • A program that runs but shows its messages in the wrong order contains a logic error.
  • Common sequence mistakes: displaying something before setting it, printing before processing the data, asking for input after trying to use it.
  • A welcome message that shows user must come after the input is stored in user. Printing it first results in an error.
  • Debugging is finding and fixing errors, and spotting a wrong sequence of instructions is an important part of it.
  • Have a goYour program runs to the end but its messages come out in the wrong order. Is there anything left to debug?

    Yes. It has a logic error to find and fix.

    Errors can stop a program running or make it give the wrong output, and debugging covers both.

The big picture

A program runs its lines from top to bottom, one at a time, exactly as they are written. So the order is 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 an important 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 the output.
3A wrong order gives unexpected or incorrect results. If the program runs but the messages are in the wrong order, it has a logic error.
4The correction for a sequence logic error is to place 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 are written as: print("Lift off!"), print(2), print(3), print(1). Put the lines in the right order.

⚠ Watch out

Thinking that a program with every necessary line will work whatever their order. The computer does exactly what it is told, in the order it is told, so a wrong order changes the steps and the output.

🧠

Memory hook

Top to bottom, exactly as told. The computer never reorders for you.

✓

Check yourself

Line 1 is print("Bye") and line 2 is print("Hi"), but the programmer wanted Hi first. What shows first, and what is the fix? Answer: Bye shows first. Put the lines in the correct order.

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?
The output appears in the same order as the instructions in the program.
Why does 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 that changes the output.
If a program has every line it needs, will it work?
Not necessarily. Having all the necessary lines is not enough if they are in the wrong order.
What do instructions in the wrong order produce?
Unexpected or incorrect results.
What is a logic error caused by wrong order?
A program that runs but produces its messages in the wrong order. The correction is to place 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?
Because user only holds the 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 the question, take the input and store it in user, then print the welcome message.
What is debugging?
Finding and fixing errors in a program.
What can errors do to a program?
Prevent 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 9 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.