Variables, DECLARE and CONSTANT · Variables, DECLARE et CONSTANT
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←.
Une variable stocke une valeur
- Une variable retient une valeur que vous pouvez utiliser et modifier.
- La flèche
←assigne une valeur à une variable (c'est l'assignation). - Sur votre clavier, tapez
<-(moins que, tiret) — cela signifie la même chose que←.
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 nomme le type
DECLAREspécifie le nom et le type de données d'une variable.- C'est une bonne pratique de déclarer une variable avant de l'utiliser.
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.
Vous pouvez changer une variable
- Réassigner pour donner une nouvelle valeur à une variable.
- Le côté droit est calculé en premier, puis stocké.
Total ← 10
Total ← Total + 5
OUTPUT Total // → 15
Watch the value change · Observer la valeur changer
← puts a value into a box. Assign again, and the box holds the new value. · ← place une valeur dans une boîte. Réassignez, et la boîte contient la nouvelle valeur.
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.
Une constante ne change pas
- Une constante est un nom pour une valeur que le programme ne doit pas changer, comme une note minimale ou un taux horaire.
- Le programme 2026–2028 écrit
CONSTANT HourlyRate ← 6.50— la flèche, puis seulement une valeur littérale. - Si le nombre change l'année prochaine, vous modifiez cette seule ligne et toutes les utilisations du nom suivent.
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.
Attention
←(ou<-) signifie stocker dans. Ce n'est pas le=utilisé pour tester l'égalité.- Une variable conserve sa dernière valeur jusqu'à ce que vous lui assigns une nouvelle.
OUTPUT Ageimprime le nombre dans la boîte.OUTPUT "Age"imprime le mot Age.
Common mistakes
DECLARE <identifier> : <data type>before you use a variable.- A constant is
CONSTANT <identifier> ← <value>. Assign a variable with←.
Erreurs courantes
DECLARE <identifier> : <data type>avant d'utiliser une variable.- Une constante est
CONSTANT <identifier> ← <value>. Assignez une variable avec←.
Now you try
- Type
<-for the←arrow. - Press Run to see the output, then Check answer.
À vous maintenant
- Tapez
<-pour la flèche←. - Appuyez sur Run pour voir la sortie, puis Check answer.
Put 16 into a variable called Age, then OUTPUT it. (Type <- for the ← arrow.) · Mettez 16 dans une variable appelée Age, puis OUTPUT-la. (Tapez <- pour la flèche ←.)
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
DECLARE a variable Price as INTEGER, set it to 3, then OUTPUT Price * 4 (the answer is 12). · DECLARE une variable Price en tant que INTEGER, définissez-la sur 3, puis OUTPUT Price * 4 (la réponse est 12).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Set · Définir Total to · à 10, then add 5 to it, then OUTPUT Total (the answer is 15). · Définissez Total sur 10, puis ajoutez 5, puis OUTPUT Total (la réponse est 15).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Declare a constant PassMark with the value 50, using ←, then OUTPUT it. · Déclarez une constante PassMark avec la valeur 50, en utilisant ←, puis OUTPUT-la.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.