Logic: AND, OR, NOT · Logique : 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 qui vérifie les deux extrémités de l'âge
- Un club accepte uniquement les membres de 11 à 16 ans. Un seul test ne peut couvrir les deux bornes.
ANDest vraiTRUEseulement si les deux tests sontTRUE:Age >= 11 AND Age <= 16.NOTinverse un booléen. Les tâches l'utilisent sur un indicateur (flag), pas sur un nombre.
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.
Un tarif dépendant de l'âge
- Le prix d'un bus est gratuit moins de 5 ans, ou à 65 ans et plus. L'un de ces tests suffit.
ORest vraiTRUEquand l'un des opérandes estTRUE.
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.
Emboîter la deuxième décision
- 80 ou plus est une distinction. Sinon, 50 ou plus est une mention, et le reste est un échec.
- La seconde
IFest l'instruction sousELSE, avec sa propreENDIF. THENreste sur la ligneIF, y compris l'imbriquation.
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.
Attention
- Écrivez la variable des deux côtés de
AND.Mark >= 0 AND <= 100n'est pas un test. - IGCSE 0478 place
THENsur la ligne suivante. Ne mélangez pas les deux épreuves.
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.
Erreurs courantes
ELSEappartient auIFqui le précède. Indentez l'intérieurIFafin que le dernierENDIFsoit celui de l'extérieur.NOTs'applique à un booléen.NOT Markn'est pas la façon de tester un nombre.
Now you try
- One task is an
OR, one is aNOT, and one is the nested grade.
À vous maintenant
- Une tâche est un
OR, une autre est unNOT, et une troisième est la note imbriquée.
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.
Alarm is a BOOLEAN set to FALSE. If NOT Alarm, output quiet, otherwise output ring. · Alarm est un ensemble BOOLEAN initialisé à FALSE. Si NOT Alarm, affichez quiet, sinon affichez ring.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Put the second IF under · sous ELSE, with THEN on the IF line. · Lisez un entier INTEGER Mark. Affichez Distinction pour 80 ou plus, sinon Pass pour 50 ou plus, sinon Fail. Placez le deuxième IF sous ELSE, avec THEN sur la ligne IF.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.