Selection: IF · Selección: SI
IF … THEN on one line
- Selection chooses what to run.
- The 2026 guide puts
THENon the same line as the condition. - The block ends at
ENDIF.
IF … THEN en una sola línea
- Selection (Selección) elige qué ejecutar.
- La guía de 2026 coloca
THENen la misma línea que la condición. - El bloque finaliza con
ENDIF.
DECLARE Age : INTEGER
Age ← 20
IF Age >= 18 THEN
OUTPUT "You may vote"
ENDIF
ELSE is the other path
ELSEruns when the condition isFALSE.- Exactly one of the two blocks runs.
- Nested
IFstatements keep the same shape.
ELSE es el otro camino
ELSEse ejecuta cuando la condición esFALSE(FALSO).- Exactamente uno de los dos bloques se ejecutará.
- Los
IFanidados mantienen la misma estructura.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
TRUE or FALSE — which block runs? · VERDADERO o FALSO — ¿qué bloque se ejecuta?
IF runs its THEN block when the test is TRUE; ELSE covers every other case. · SI ejecuta su bloque ENTONCES cuando la prueba es VERDADERA; SINO cubre todos los demás casos.
Relational operators
=equal,<>not equal,<><=>=.AND,ORandNOTare logic operators. Their operands areBOOLEAN.
Operadores relacionales
=igual,<>distinto de,<><=>=.AND,ORyNOTson operadores lógicos. Sus operandos sonBOOLEAN.
DECLARE N : INTEGER
N ← 7
IF N MOD 2 = 0 THEN
OUTPUT "even"
ELSE
OUTPUT "odd"
ENDIF
AND, OR and NOT
ANDis true only when both tests are true. A mark is in range when it is at least 0 and at most 100.ORis true when either test is true.NOTflipsTRUEandFALSE.- Write the variable on both sides.
Mark >= 0 AND Mark <= 100is the test.Mark >= 0 AND <= 100is not.
AND, OR y NOT
ANDes verdadero solo cuando ambas pruebas son verdaderas. Una nota está dentro del rango cuando es al menos 0 y a lo más 100.ORes verdadero cuando cualquiera de las pruebas es verdadera.NOTinvierteTRUE(VERDADERO) yFALSE(FALSO).- Escribe la variable en ambos lados.
Mark >= 0 AND Mark <= 100es la prueba correcta.Mark >= 0 AND <= 100no lo es.
DECLARE Mark : INTEGER
Mark ← 80
IF Mark >= 0 AND Mark <= 100 THEN
OUTPUT "valid"
ELSE
OUTPUT "invalid"
ENDIF
Watch out
THENstays on theIFline. IGCSE 0478 putsTHENon the following line. Do not mix them.- In a test,
=means "is equal to". Storing a value still uses←. "Pass"and"Fail"need quotes.OUTPUT Passlooks up a name called Pass.
Precaución
THENpermanece en la línea delIF. IGCSE 0478 colocaTHENen la línea siguiente. No los mezcles.- En una prueba,
=significa "es igual a". Almacenar un valor sigue usando←. "Pass"y"Fail"necesitan comillas.OUTPUT Passbuscaría un nombre llamado Pass.
Common mistakes
- Every
IFneeds anENDIF. ELSEbelongs to theIFabove it, not to a nested one, unless you indent it that way.
Errores comunes
- Todo
IFnecesita su correspondienteENDIF. ELSEpertenece alIFsuperior, no a uno anidado, a menos que lo indentes así.
Now you try
- Read a number and choose with
IF…THEN…ELSE…ENDIF.
Ahora tú intentas
- Lee un número y decide con
IF...THEN...ELSE...ENDIF.
Read an INTEGER Mark. Output "Pass" when it is at least 50, otherwise "Fail". · Lee un INTEGER Mark. Salida "Pass" cuando sea al menos 50, de lo contrario "Fail".
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Read an INTEGER N. Output positive when it is greater than 0, otherwise not positive. · Lee un INTEGER N. Emite positive cuando es mayor que 0, de lo contrario not positive.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Read an INTEGER Mark. Output valid when it is from 0 to · hasta 100 inclusive, using AND. Otherwise output invalid. · Lee un INTEGER Mark. Emite valid cuando está entre 0 y 100 inclusive, usando AND. De lo contrario emite invalid.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.