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 A2 total = 03 score = 124 bonus = 85 total = score + bonus6 print("Your total is:")7 print(total)8 // Version B: the same six lines, two of them swapped9 total = 010 score = 1211 bonus = 812 print(total)13 print("Your total is:")14 total = score + bonus
| version | score | bonus | total |
|---|---|---|---|
| A | 0 |
Output
Step 1: Version A. The first instruction runs: total starts at 0. Nothing has been added yet.
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.
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?
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
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?
In what order does a program run its statements?
Why do a program's instructions need to be precise?
In what order does a program's output appear?
What happens when you change the sequence of the code?
What do instructions in the wrong order produce?
What is debugging?
Name an important part of debugging linked to sequence.
A program runs but gives an incorrect result because lines are in the wrong order. What kind of error is it?
Give two examples of a sequence logic error.
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 OCR GCSE Computer Science topics
- Data type: Real
- File handling: open, read, write, close
- Inputs, outputs, assignments
- Iteration (count- and condition-controlled loops)
- Local and global variables
- Operators (arithmetic and Boolean)
- Random number generation
- Records
- SQL: SELECT, FROM, WHERE
- Sub programs: functions
- Sub programs: procedures
- Variables
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.