Variables, DECLARE and CONSTANT
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
A variable stores a value
- A variable holds a value you can use and change.
- The arrow
←puts a value into a variable (this is assignment). - On your keyboard, type
<-(less-than, minus) — it means the same as←.
Age ← 16
OUTPUT Age // → 16
OUTPUT "Age" // → Age
DECLARE names the type
DECLAREstates a variable's name and its data type.- It is good style to declare a variable before you use it.
DECLARE Count : INTEGER
Count ← 0
OUTPUT Count // → 0
You can change a variable
- Assign again to give a variable a new value.
- The right-hand side is worked out first, then stored.
Total ← 10
Total ← Total + 5
OUTPUT Total // → 15
Explore · 探索
Watch the value change
← puts a value into a box. Assign again, and the box holds the new value.
A constant does not change
- A constant is a name for a value the program must not change, such as a pass mark or an hourly rate.
- The 2026–2028 syllabus writes
CONSTANT HourlyRate ← 6.50— the arrow, then a literal only. - If the number changes next year, you edit that one line and every use of the name follows.
CONSTANT PassMark ← 50
OUTPUT PassMark // → 50
Watch out
←(or<-) means store into. It is not the=used to test equality.- A variable keeps its last value until you assign a new one.
OUTPUT Ageprints the number in the box.OUTPUT "Age"prints the word Age.
Common mistakes
DECLARE <identifier> : <data type>before you use a variable.- A constant is
CONSTANT <identifier> ← <value>. Assign a variable with←.
Now you try
- Type
<-for the←arrow. - Press Run to see the output, then Check answer.
Put 16 into a variable called Age, then OUTPUT it. (Type <- for the ← arrow.)
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
DECLARE a variable Price as INTEGER, set it to 3, then OUTPUT Price * 4 (the answer is 12).
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Set Total to 10, then add 5 to it, then OUTPUT Total (the answer is 15).
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Declare a constant PassMark with the value 50, using ←, then OUTPUT it.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。