Logic: AND, OR, NOT · Lógica: AND, OR, NOT
A club that checks both ends of the age
- A club takes members only from 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE:Age >= 11 AND Age <= 16.NOTflips a Boolean. The tasks use it on a flag, not on a number.
Un club que verifica ambos extremos de la edad
- Un club solo acepta miembros entre 11 y 16 años. Una sola prueba no puede verificar ambos extremos.
ANDesTRUEsolo cuando ambas pruebas sonTRUE:Age >= 11 AND Age <= 16.NOTinvierte un valor Booleano. Las tareas lo aplican a una bandera, no a un número.
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16 THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
A fare that depends on either age
- A bus fare is free under 5, or at 65 and over. One of those tests is enough.
ORisTRUEwhen either operand isTRUE.
Una tarifa que depende de la edad
- El pasaje del autobús es gratuito para menores de 5 años, o a partir de los 65. Basta con que se cumpla uno de esos criterios.
OResTRUEcuando al menos uno de sus operandos esTRUE.
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65 THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
Nest the second decision
- 80 or more is a distinction. Otherwise, 50 or more is a pass, and the rest is a fail.
- The second
IFis the statement underELSE, with its ownENDIF. THENstays on theIFline, including the inner one.
Anidar la segunda decisión
- 80 o más es una distinción. De lo contrario, 50 o más es un aprobado, y el resto es un suspenso.
- El segundo
IFes la instrucción dentro delELSE, con su propioENDIF. THENpermanece en la línea delIF, incluido el anidado.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 80 THEN
OUTPUT "Distinction"
ELSE
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
Watch out
- Write the variable on both sides of
AND.Mark >= 0 AND <= 100is not a test. - IGCSE 0478 puts
THENon the following line. Do not mix the two papers.
Cuidado
- Escribe la variable en ambos lados de
AND.Mark >= 0 AND <= 100no es una prueba válida. - IGCSE 0478 coloca
THENen la línea siguiente. No mezcles los dos formatos.
Common mistakes
ELSEbelongs to theIFabove it. Indent the innerIFso the finalENDIFis the outer one.NOTapplies to a Boolean.NOT Markis not how you test a number.
Errores comunes
ELSEpertenece alIFinmediatamente superior. Indenta elIFinterno para que el últimoENDIFcorresponda al exterior.NOTse aplica a un valor Booleano.NOT Markno es la forma correcta de probar un número.
Now you try
- One task is an
OR, one is aNOT, and one is the nested grade.
Ahora tú intentas
- Una tarea es un
OR, otra es unNOTy la tercera es la calificación anidada.
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · Lee un INTEGER Age. Imprime free cuando Age sea menor que 5 o al menos 65, usando OR. De lo contrario, imprime pay.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Alarm is a BOOLEAN set to FALSE. If NOT Alarm, output quiet, otherwise output ring. · Alarm es un BOOLEAN configurado en FALSE. Si NOT Alarm, imprime quiet, de lo contrario imprime ring.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Put the second IF under · debajo de ELSE, with THEN on the IF line. · Lee un INTEGER Mark. Imprime Distinction para 80 o más, de lo contrario imprime Pass para 50 o más, de lo contrario imprime Fail. Coloca el segundo IF bajo ELSE, con THEN en la línea del IF.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.