LES OPERATEURS AND, OR ET NOT
Les mots-clés AND, OR et NOT sont utilisés comme des opérateurs permettant de
combiner des expressions booléennes. Voici différents exemples de ces opérateurs
utilisés au sein d'une instruction conditionnelle.
AND L'instruction est exécutée si et seulement si les deux conditions
sont vraies,
if (A = 1) AND (B = 2) then writeln('Bingo!');
OR L'instruction est exécutée si au moins UN des arguments est vrai.
if (A = 1) OR (B = 2) then writeln('Hurray!');
NOT L'instruction est exécutée si (A = 1) est FALSE.
if NOT (A = 1) then writeln('Wow, really heavy man!');
program AND_OR_NOT_DEMO (output);
var a, b, c : integer;
begin
a := 5; b := 3; c := 99;
if (a = 5) or (b > 2) then writeln('A');
if (a < 5) and (b > 2) then writeln('B');
if (a = 5) and (b = 2) then writeln('C');
if (c <> 6) or (b > 10) then writeln('D') else writeln('E');
if (b = 3) and (c = 99) then writeln('F');
if (a = 1) or (b = 2) then writeln('G');
if not( (a < 5) and (b > 2)) then writeln('H')
end.
Cliquez ici pour afficher la réponse