In addition to the comparison operators that produce boolean results (usually comparing numeric values), there are three boolean operators that take boolean values as operands and produce boolean results.
Operator Meaning &&
AND: both operands must be true
for the whole expression to betrue
||
OR: one or the other operand must be true
for the whole expression to betrue
(vertical bars are usually above the\
symbol on the keyboard)!
NOT (negation): if the operand is true
then the expression isfalse
; if the operand isfalse
then the expression istrue
.Examples:
if ( ( 0 < i ) && ( i < k ) ) { ... } if ( fish.atWall() || ( randNum < 2 ) ) { ... } if ( ( hour > 6 ) && ( ! todayIsSunday ) ) { ... }