Variables, DECLARE and CONSTANT · Variables, DECLARE y 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←.
Una variable almacena un valor
- Una variable guarda un valor que puedes usar y modificar.
- La flecha
←introduce un valor en una variable (esto es una asignación). - En tu teclado, escribe
<-(menor que, guion) — significa lo mismo 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 nombra el tipo
DECLAREespecifica el nombre de una variable y su tipo de dato.- Es buena práctica declarar una variable antes de usarla.
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.
Puedes cambiar una variable
- Vuelve a asignar para darle a una variable un nuevo valor.
- El lado derecho se calcula primero, luego se almacena.
Total ← 10
Total ← Total + 5
OUTPUT Total // → 15
Watch the value change · Observa cómo cambia el valor
← puts a value into a box. Assign again, and the box holds the new value. · ← introduce un valor en una caja. Si se asigna de nuevo, la caja contiene el nuevo valor.
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.
Una constante no cambia
- Una constante es un nombre para un valor que el programa no debe modificar, como una nota aprobatoria o una tarifa por hora.
- El plan de estudios 2026–2028 usa
CONSTANT HourlyRate ← 6.50— la flecha, seguida solo de un literal. - Si el número cambia el próximo año, editas esa única línea y todos los usos del nombre se actualizan automáticamente.
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.
Ten cuidado
←(o<-) significa almacenar en. No es el=usado para comprobar igualdad.- Una variable mantiene su último valor hasta que le asignas uno nuevo.
OUTPUT Ageimprime el número dentro de la caja.OUTPUT "Age"imprime la palabra Edad.
Common mistakes
DECLARE <identifier> : <data type>before you use a variable.- A constant is
CONSTANT <identifier> ← <value>. Assign a variable with←.
Errores comunes
DECLARE <identifier> : <data type>antes de usar una variable.- Una constante es
CONSTANT <identifier> ← <value>. Asigna a una variable con←.
Now you try
- Type
<-for the←arrow. - Press Run to see the output, then Check answer.
Ahora practica
- Escribe
<-en lugar de la flecha←. - Pulsa Ejecutar para ver la salida, luego Comprobar respuesta.
Put 16 into a variable called Age, then OUTPUT it. (Type <- for the ← arrow.) · Asigna 16 a una variable llamada Age, luego OUTPUTla. (Usa <- para la flecha ←).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
DECLARE a variable Price as INTEGER, set it to 3, then OUTPUT Price * 4 (the answer is 12). · DECLARE una variable Price como INTEGER, asígnale el valor 3, luego OUTPUT Price * 4 (la respuesta es 12).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Set · Conjunto Total to · hasta 10, then add 5 to it, then OUTPUT Total (the answer is 15). · Asigna 10 a Total, luego súmale 5, y finalmente OUTPUT Total (la respuesta es 15).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Declare a constant PassMark with the value 50, using ←, then OUTPUT it. · Declara una constante PassMark con el valor 50, usando ←, luego OUTPUT.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.