GCSE · Computer Science · OCR · Spec J277

Sequence

Print the total before you add it up, and the program cheerfully prints the wrong answer. It runs right to the end, and it's still wrong. Welcome to sequence.

Computer Science · Sequence

Same six lines, two different answers

Version A adds up first, then prints. Version B has exactly the same lines with two of them swapped. Step through both, one line at a time.

Version B prints the same two things as Version A, right? Step through A, then decide before you run B.

1 // Version A
2 total = 0
3 score = 12
4 bonus = 8
5 total = score + bonus
6 print("Your total is:")
7 print(total)
8 // Version B: the same six lines, two of them swapped
9 total = 0
10 score = 12
11 bonus = 8
12 print(total)
13 print("Your total is:")
14 total = score + bonus
versionscorebonustotal
A0

Output

 

Step 1: Version A. The first instruction runs: total starts at 0. Nothing has been added yet.

1 / 12

Press Next to run one line. The highlighted line is the one running, the table shows what changed, and the output box is the screen.

Step 1 of 12: Version A. The first instruction runs: total starts at 0. Nothing has been added yet..

Watch out: Version B runs right to its last line without stopping, and still prints 0 instead of 20. Running is not the same as right.

Predict, then check

Run it in your head first: top line, then the next, then the next.

coins = 3, then coins = coins + 2, then coins = coins * 10, then print(coins). These four lines run in that order. What gets printed?

Your turn to sequence

Unscramble the savings program

Put the five lines in the order that makes the program print: Start: 50, then After top-up: 70, then Thanks for saving!

1 · Runs first5 · Runs last
  1. balance = balance + 20

  2. print("Thanks for saving!")

  3. balance = 50

  4. print("After top-up:", balance)

  5. print("Start:", balance)

Watch out: Every line here is correct on its own. Only the order can go wrong.

Debugging

Which line is in the wrong place?

This program should print Price to pay:, then 8, then Enjoy the film!. It runs to the end, but it prints 10 instead of 8. Which ONE line needs to move?

A program with one line out of place — which line goes wrong?

Before you trust it

It ran. So it's fine?

Ella's quiz program runs all the way to the end. No error message. But it prints "Quiz over, well done!" before it prints "Question 1".

Which is closest to what you think right now?
How sure are you?

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

A computer does exactly what you tell it, in exactly the order you tell it. Swap two lines and you change what it does.

What you need to know

  • Sequence is the order of the commands in a program.
  • A program runs from top to bottom, one statement at a time, in the order you wrote them.
  • Have a goA program has five lines. Line 4 is print("Hi"). When Hi appears on the screen, how many lines have already finished running?

    Three: lines 1, 2 and 3.

    Top to bottom, one at a time: line 4 has to wait for the three lines above it. Saying four counts line 4 as finished before it has even printed.

  • Each line runs in turn: line 3 doesn't start until lines 1 and 2 are done.
  • The computer does exactly what the instructions say, so they need to be precise.
  • Output appears in the same order as the instructions in the program.
  • Have a goYour friend writes print("Bye!") on line 1 and print("Hello!") on line 2, then insists the computer will be polite and say Hello! first. Will it?

    No. Bye! comes out first, then Hello!

    The output follows the order of the instructions. The computer doesn't tidy things up into what you meant; it just runs the lines as written.

  • Change the sequence and you change the steps the computer takes, so the output can change too.
  • Have a goThree lines: print("A"), print("B"), print("C"). Swap the first and last lines. What does the screen show now?

    C, then B, then A.

    Same three instructions, new order, so the output order changes with them. B stays in the middle because its line didn't move.

  • Instructions in the wrong order give unexpected or incorrect results.
  • Debugging means finding and fixing errors in a program. Spotting a wrong sequence is an important part of it.
  • A program in the wrong order can still run and give an incorrect result. That's a logic error.
  • Classic examples: messages displayed in the wrong order, or printing output before the data is processed.

The big picture

Sequence is the order of the commands in a program. The computer runs them from top to bottom, one statement at a time, exactly as written, so the order you choose decides the steps it takes and the output you get. Lines in the wrong order can still run and give an incorrect result: a logic error, which you find and fix by debugging.

Key points

1Sequence = the order of commands. They run top to bottom, one at a time.
2The computer does exactly what it's told, and the output comes out in instruction order.
3Swap lines and you change the steps, so the output can change too.
4Wrong order can run happily and still give the wrong result: a logic error.
5Debugging = finding and fixing errors. Checking the order is a big part of it.

Worked example

Problem

This program should print Welcome back!, then the score 7, then Goodbye!. Here it is: line 1 score = 7; line 2 print("Goodbye!"); line 3 print("Welcome back!"); line 4 print(score). Work out what it really prints, then fix it.

⚠ Watch out

Trusting a program just because it ran. Instructions in the wrong order don't stop a program: it can run to the end and still give an incorrect result. That's a logic error, so always compare what it actually output with what you meant it to output.

🧠

Memory hook

Top to bottom, one at a time, exactly as written. Print it before you work it out, and you print the wrong thing.

✓

Check yourself

Cover the page. Can you define sequence, say how a program runs its statements, explain what swapping two lines can do, and say why a program that runs can still be wrong?

Flashcards

(10)
What does sequence mean in programming?
The order of the commands in a program.
In what order does a program run its statements?
From top to bottom, one statement at a time, in the order they are written.
Why do a program's instructions need to be precise?
Because the computer executes instructions exactly as they are given.
In what order does a program's output appear?
In the same order as the instructions in the program.
What happens when you change the sequence of the code?
The computer takes different steps, so the output can change.
What do instructions in the wrong order produce?
Unexpected or incorrect results.
What is debugging?
The process of finding and fixing errors in a program.
Name an important part of debugging linked to sequence.
Identifying an incorrect sequence of instructions.
A program runs but gives an incorrect result because lines are in the wrong order. What kind of error is it?
A logic error.
Give two examples of a sequence logic error.
Messages displayed in the wrong order; printing output before the data has been processed.

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

See the full OCR Computer Science curriculum →

How this lesson was checked. This OCR GCSE Computer Science (specification J277)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 3 November 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.