Logic: AND, OR, NOT · Lógica: AND, OR, NOT
A club that checks your age
- A coding club takes members only from age 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE.- Write the variable on each side:
Age >= 11 AND Age <= 16.
Um clube que verifica sua idade
- Um clube de programação recebe membros apenas da idade 11 a 16. Um teste não pode dizer ambos os extremos.
ANDéTRUEapenas quando ambos os testes sãoTRUE.- Escreva a variável de cada lado:
Age >= 11 AND Age <= 16.
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16
THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
OR: either test is enough
- A bus fare is free for a child or a senior: under 5, or 65 and over.
ORisTRUEwhen at least one test isTRUE.
OR: qualquer teste basta
- A tarifa de ônibus é gratuita para uma criança ou idoso: abaixo de 5, ou 65 e acima.
ORéTRUEquando pelo menos um teste éTRUE.
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65
THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
NOT flips a Boolean
NOTturnsTRUEintoFALSE, andFALSEintoTRUE.- A search that has not found the target yet is
NOT Found.
NOT inverte um Boolean
NOTtransformaTRUEemFALSE, eFALSEemTRUE.- Uma busca que ainda não encontrou o alvo é
NOT Found.
DECLARE Found : BOOLEAN
Found ← FALSE
IF NOT Found
THEN
OUTPUT "missing"
ENDIF
Watch out
Mark >= 0 AND <= 100is not a test. The second half has nothing to compare.- Parentheses make a mix obvious:
NOT (Age < 11 OR Age > 16).
Atenção
Mark >= 0 AND <= 100não é um teste. A segunda metade não tem nada com que comparar.- Parênteses tornam uma mistura óbvia:
NOT (Age < 11 OR Age > 16).
Common mistakes
AND,ORandNOTare keywords. Their operands areBOOLEAN, usually from a relational test.9618putsTHENon theIFline. This course keepsTHENon the next line.
Erros comuns
AND,OReNOTsão palavras-chave. Seus operandos sãoBOOLEAN, geralmente de um teste relacional.9618colocaTHENna linhaIF. Este curso mantémTHENna linha seguinte.
Now you try
- Each task is one decision. Write both sides of
ANDand ofOR. - Press Check answer to test it.
Agora você tenta
- Cada tarefa é uma decisão. Escreva ambos os lados de
ANDe deOR. - Pressione Check answer para testá-lo.
Read an INTEGER Age. Output accepted when it is from 11 to · até 16 inclusive, using AND. Otherwise output no. · Leia um inteiro INTEGER Age. Imprima accepted se estiver de 11 a 16 inclusivo, usando AND. Caso contrário, imprima no.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
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.
Found is a BOOLEAN set to FALSE. If NOT Found, output missing. · Found é um conjunto BOOLEAN definido como FALSE. Se NOT Found, imprima missing.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.