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.
Um clube que verifica ambas as extremidades da idade
- Um clube aceita membros apenas de 11 a 16. Um teste não pode dizer ambas as extremidades.
ANDéTRUEapenas quando ambos os testes sãoTRUE:Age >= 11 AND Age <= 16.NOTinverte um Boolean. As tarefas usam isso em uma flag, não em um 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.
Uma tarifa que depende de qualquer idade
- A tarifa de ônibus é gratuita abaixo de 5 anos, ou aos 65 anos e acima. Um desses testes é suficiente.
ORéTRUEquando qualquer operando éTRUE.
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.
Anide a segunda decisão
- 80 ou mais é distinção. Caso contrário, 50 ou mais é aprovação, e o resto é reprovação.
- O segundo
IFé a instrução sobELSE, com seu próprioENDIF. THENfica na linhaIF, incluindo o interna.
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.
Atenção
- Escreva a variável em ambos os lados de
AND.Mark >= 0 AND <= 100não é um teste. - IGCSE 0478 coloca
THENna linha seguinte. Não misture os dois exames.
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.
Erros comuns
ELSEpertence aoIFacima dele. Recue oIFinterno para que oENDIFfinal seja o externo.NOTse aplica a um Boolean.NOT Marknão é como testar um número.
Now you try
- One task is an
OR, one is aNOT, and one is the nested grade.
Agora você tenta
- Uma tarefa é um
OR, outra é umNOT, e outra é a nota aninhada.
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · Leia um INTEGER Age. Saia free quando Age estiver abaixo de 5 ou pelo menos 65, usando OR. Caso contrário, saia pay.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Alarm is a BOOLEAN set to FALSE. If NOT Alarm, output quiet, otherwise output ring. · Alarm é um conjunto BOOLEAN definido como FALSE. Se NOT Alarm, imprima quiet, caso contrário imprima ring.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Put the second IF under · sob ELSE, with THEN on the IF line. · Leia um inteiro INTEGER Mark. Imprima Distinction para 80 ou mais, caso contrário Pass para 50 ou mais, caso contrário Fail. Coloque o segundo IF sob ELSE, com THEN na linha IF.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.