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?

1constant TICKET_PRICE = 8
2total = 0
3FOR ticket = 1 TO 3
4 total = total + TICKET_PRICE
5NEXT ticket
6OUTPUT total
TICKET_PRICE
ticket
total
Output
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

What really makes it a constant?

Why did TICKET_PRICE never move?

In the ticket program, TICKET_PRICE stayed at 8 on every row of the trace table while total and ticket kept changing.

Which is closest to what you think right now? TICKET_PRICE is a constant because…
How sure are you?

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.

6 of 6 still to sort.

The items are described in plain words on purpose, so you judge by how each value behaves, not by how its name looks.

Updating the program

Version 2 needs a new time limit

Version 1 of the quiz uses the 30-second time limit in 12 different lines. For version 2 it must become 20 seconds. If version 1 had used a constant, TIME_LIMIT, declared once at the start, how many lines would you have to edit?

Your estimate

7 lines

0 lines13 lines

Protected from mistakes

Catch the slip

This code should count down the time for one quiz question. One line breaks the rule of a constant. Which one?

A programmer's first attempt — which line goes wrong?

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

1Declaration = identifier + value, written before the constant is first used, e.g. constant MAX_PLAYERS = 4.
2Constant or variable? Ask whether the program may change the value while it runs, not whether it happens to.
3Readable: a meaningful identifier explains what the value represents.
4Maintainable: a value that changes between versions is edited in one place, the declaration.
5Safe: a line that tries to reassign a constant breaks the rule, so the value can't be changed by mistake during execution.
6CAPITALS for constant identifiers are a common convention to make them stand out, not the thing that makes them constant.

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?
A named value: an identifier linked to a value that is fixed when the constant is declared.
What happens when you declare a constant?
You create it by giving it an identifier and assigning its value, usually near the start of the program, before it is used.
Constant vs variable: what's the difference?
A variable's value can change while the program runs. A constant's value cannot.
A value in your program never happens to change. Does that make it a constant?
No. Only a value declared as a constant is one. A variable that no line happens to update is still a variable.
Do capital letters make an identifier a constant?
No. CAPITALS are a naming convention that makes constants easy to spot. The declaration is what makes it a constant.
How does a constant make code easier to read?
Its meaningful identifier explains what the value represents, e.g. TIME_LIMIT instead of a bare 30.
How does a constant make a program easier to maintain?
If the value must change for a new version, you edit one line, the declaration, instead of every place the value was typed.
How does a constant make a program safer?
It can't be reassigned while the program runs, so its value can't be changed by mistake during execution.
Quiz game: the time limit per question, or the time left on it. Which should be the constant?
The time limit. It is fixed for the whole run. The time left counts down, so it must be a variable.
Can a programmer ever change a constant's value?
Yes, by editing its declaration between versions of the program. The running program can't change it.
In a trace table, how do you spot a constant's column?
It holds the value it was given at declaration on every row, while variables' columns change.

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

See the full AQA Computer Science curriculum →

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.