Logic: AND, OR, NOT · Logique : 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.
Un club qui vérifie votre âge
- Un club de codage n'accepte des membres que de l'âge 11 à 16. Un test ne peut pas dire les deux extrémités.
ANDestTRUEseulement lorsque les deux tests sontTRUE.- Écrivez la variable de chaque côté :
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 : soit un test suffit
- Un tarif de bus est gratuit pour un enfant ou un senior : moins de 5 ans, ou 65 ans et plus.
ORestTRUElorsque au moins un test estTRUE.
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 inverse un Booléen
NOTtransformeTRUEenFALSE, etFALSEenTRUE.- Une recherche qui n'a pas encore trouvé la cible est
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).
Attention
Mark >= 0 AND <= 100n'est pas un test. La seconde partie n'a rien à comparer.- Les parenthèses rendent un mélange évident :
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.
Erreurs courantes
AND,ORetNOTsont des mots-clés. Leurs opérandes sontBOOLEAN, généralement issus d'un test relationnel.9618placeTHENsur la ligneIF. Ce cours gardeTHENsur la ligne suivante.
Now you try
- Each task is one decision. Write both sides of
ANDand ofOR. - Press Check answer to test it.
À vous maintenant
- Chaque tâche est une décision. Écrivez les deux côtés de
ANDet deOR. - Appuyez sur Vérifier la réponse pour tester.
Read an INTEGER Age. Output accepted when it is from 11 to · à 16 inclusive, using AND. Otherwise output no. · Lisez un entier INTEGER Age. Affichez accepted s'il est compris entre 11 et 16 inclus, en utilisant AND. Sinon affichez no.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · Lisez un entier INTEGER Age. Affichez free quand Age est inférieur à 5 ou supérieur ou égal à 65, en utilisant OR. Sinon affichez pay.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Found is a BOOLEAN set to FALSE. If NOT Found, output missing. · Found est une BOOLEAN définie comme FALSE. Si NOT Found, afficher missing.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.