GCSE · Computer Science · AQA · Spec 8525
Constant declaration
Some values should never budge while a program runs, like a ticket price. So how do you tell the program 'this one stays put'? Pin it to a name, once.
Computer Science · Algorithms
Trace table — dry run the code
Press Start and step through. Watch all three columns. Two of them keep changing. One never moves. Which one, and why?
Ready when you are — step through one line at a time.
Constant or variable?
Sort the values in a quiz game
You're writing a timed quiz game. Pick each value, then decide: constant or variable?
Still to sort
Constant (0)
Stays the same for the whole time the program runs.
Where the line is: If any line needs to give it a new value while the program is running, it cannot be a constant.
Variable (0)
Needs to change while the program runs.
Where the line is: A variable can start with a fixed first value (like 0) and still be a variable, because it changes later.
The values are described in plain words on purpose, so you judge by how each one behaves, not by how its name looks.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Pin a name to a value once, and the program can't move it while it runs.
What you need to know
- A constant is a named value: an identifier gets linked to a value when the constant is declared.
- Declaring one means giving it an identifier and its fixed value, usually near the start, before anything uses it.
- Once the program is running, nothing can change a constant's value.
Have a goGame dev hack: halfway through a level, a line tries GRAVITY = 0 so the hero can float. GRAVITY was declared as a constant. Is that line allowed?
No. That line breaks the rule of a constant.
It's tempting to think a line runs just because it's written. But GRAVITY was declared as a constant, so no line may give it a new value while the program is running.
- A variable is the opposite: its value can change during execution.
- Declaration is the test, not luck. A variable that no line happens to update is still a variable.
Have a goA trace table shows LIVES as 3, 3, 3, 3 and round as 1, 2, 3, 4. Which one could be a constant, and can you be sure just from the table?
Only LIVES could be. To be sure, check how it was declared.
round changes, so it must be a variable. But a value that stays the same might just be a variable nobody updated: only the declaration settles it.
- Give constants meaningful identifiers. Writing them in CAPITALS, like VAT_RATE, is a common convention so they stand out.
Have a goA constant holds the 5 lives each player starts with. Rank these names, best to worst: X, lives5, MAX_LIVES.
MAX_LIVES, then lives5, then X.
MAX_LIVES says what the 5 means and uses capitals so it stands out. lives5 just repeats the number, and X tells a reader nothing at all.
- Easier to read: a name like VAT_RATE tells you what the value means, where a bare number leaves you guessing.
- Easier to maintain: if the value changes in a new version, you edit one place, the declaration.
- Safer: no line can reassign a constant mid-run, so its value can't be changed by mistake.
The big picture
A constant is a named value: you give it an identifier and a value when you declare it, usually near the start of the program, and after that the program is not allowed to change it while it runs. A variable's value can change during execution; a constant's cannot. Using constants makes code easier to read, easier to update between versions, and safer from accidental changes.
Key points
Worked example
Problem
A shop program adds a delivery charge of 4 to three totals, typing the 4 straight into each line: bikeTotal = bikePrice + 4; bookTotal = bookPrice + 4; lampTotal = lampPrice + 4. Rewrite it using a constant, then say which line you would edit if the delivery charge went up to 5.
⚠ Watch out
Thinking a constant can never be changed by anyone. Looks right. It isn't. The rule is about the running program: no line may give a constant a new value during execution. You, the programmer, can still change the value between versions of the program by editing its declaration.
Memory hook
Pin it once, read it anywhere. A constant is pinned at the top when it's declared. The running program can read the pin but can never move it. Only you can re-pin it, by editing the declaration.
Check yourself
Without looking back: what two things does a constant declaration give the program, and what is the one thing the running program is never allowed to do to a constant?
Flashcards
(11)What is a constant?
What happens when you declare a constant?
Constant vs variable: what's the difference?
A value in your program never happens to change. Does that make it a constant?
Do capital letters make an identifier a constant?
How does a constant make code easier to read?
How does a constant make a program easier to maintain?
How does a constant make a program safer?
Quiz game: the time limit per question, or the time left on it. Which should be the constant?
Can a programmer ever change a constant's value?
In a trace table, how do you spot a constant's column?
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 AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 28 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.