Pensez à !
(opérateur de négation) comme "not", ||
(opérateur booléen-or) comme "ou" et &&
(opérateur booléen-et) comme "et". Voir Opérateurs y Priorité de l'opérateur .
Ainsi :
if(!(a || b)) {
// means neither a nor b
}
Cependant, l'utilisation de La loi de Morgan On pourrait l'écrire comme suit
if(!a && !b) {
// is not a and is not b
}
a
y b
ci-dessus peut être n'importe quelle expression (telle que test == 'B'
ou ce qu'il faut).
Une fois de plus, si test == 'A'
y test == 'B'
sont les expressions, notez l'expansion de la 1ère forme :
// if(!(a || b))
if(!((test == 'A') || (test == 'B')))
// or more simply, removing the inner parenthesis as
// || and && have a lower precedence than comparison and negation operators
if(!(test == 'A' || test == 'B'))
// and using DeMorgan's, we can turn this into
// this is the same as substituting into if(!a && !b)
if(!(test == 'A') && !(test == 'B'))
// and this can be simplified as !(x == y) is the same as (x != y)
if(test != 'A' && test != 'B')