Selection: IF · Sélection : IF
IF makes a decision
- Selection chooses what to do, based on a test.
IFruns itsTHENblock only when the test isTRUE.- The block ends at
ENDIF.
IF prend une décision
- La sélection choisit quoi faire, basé sur un test.
IFexécute son blocTHENuniquement quand le test estTRUE.- Le bloc se termine à
ENDIF.
DECLARE Age : INTEGER
Age ← 20
IF Age >= 18
THEN
OUTPUT "You may vote"
ENDIF
IF ... ELSE
ELSEgives the path to take when the test isFALSE.- Exactly one of the two blocks runs.
IF ... ELSE
ELSEdéfinit le chemin à suivre quand le test estFALSE.- Exactement un des deux blocs s'exécute.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
TRUE or FALSE — which block runs? · VRAI ou FAUX — quel bloc s'exécute ?
IF runs its THEN block when the test is TRUE; ELSE covers every other case. · IF exécute son bloc THEN quand le test est TRUE ; ELSE couvre tous les autres cas.
Comparison operators
=equal to,<>not equal to.<><=>=compare sizes.
Opérateurs de comparaison
=égal à,<>différent de.<><=>=comparer des tailles.
DECLARE N : INTEGER
N ← 7
IF MOD(N, 2) = 0
THEN
OUTPUT "even"
ELSE
OUTPUT "odd"
ENDIF
Watch out
- In a test,
=means "is equal to". (The arrow←is for storing a value.) - Don't forget
THENafter the test andENDIFto close the block.
Attention
- Dans un test,
=signifie « est égal à ». (La flèche←sert à stocker une valeur.) - N'oubliez pas
THENaprès le test etENDIFpour fermer le bloc.
Common mistakes
- Write
IF ... THEN ... ELSE ... ENDIF— do not forgetENDIF. - Compare with
=in pseudocode conditions.
Erreurs courantes
- Écrivez
IF ... THEN ... ELSE ... ENDIF— n'oubliez pasENDIF. - Comparer avec
=dans les conditions en pseudocode.
Now you try
- Read the input, then choose with
IF ... ELSE ... ENDIF. - Press Check answer to test it.
À vous maintenant
- Lisez l'entrée, puis choisissez avec
IF ... ELSE ... ENDIF. - Appuyez sur Vérifier la réponse pour tester.
Read an INTEGER N. If it is greater than 0, output positive, otherwise output not positive. For input 5, output positive. · Lisez un INTEGER N. Si c'est supérieur à 0, affichez positive, sinon affichez not positive. Pour l'entrée 5, affichez positive.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Read a Mark. Output Pass if it is 50 or more, otherwise Fail. For input 40, output Fail. · Lisez un Mark. Affichez Pass si c'est 50 ou plus, sinon Fail. Pour l'entrée 40, affichez Fail.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Read an INTEGER N. Output even if · si N MOD 2 = 0, otherwise odd. For input 8, output even. · Lisez un INTEGER N. Affichez even si N MOD 2 = 0, sinon odd. Pour l'entrée 8, affichez even.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.