GCSE · Computer Science · AQA · Spec 8525
Constant declaration
Some values should never move 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
A programmer is writing a timed quiz game. Pick each value, then decide: should it be a constant or a 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 items are described in plain words on purpose, so you judge by how each value 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 is linked to a value when the constant is declared.
- A constant's value cannot be changed while the program is running. A variable's value can.
- Declare a constant by giving it an identifier and its fixed value, usually near the start of the program, before it is used.
- Constants make code easier to read, easier to update and safer from accidental changes.
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. 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 30 September 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.