Logical operators normally take relational expressions as operands. The ! operator takes one operand. The rest take two: one to the left, and one to the right.
&& | AND |
|| | OR |
! | NOT |
expression1 && expression2 is true if, and only if, both expressions are true. |
expression1 || expression2 is true if either one or both expressions are true. |
!expression is true if the expression is false, and vice versa. |
Logical expressions are evaluated from left to right. Evaluation stops as soon as something is discovered that renders the expression false.
6 > 2 && 3 == 3 is true. |
! ( 6 > 2 && 3 == 3 ) is false. |
x != 0 && 20/x < 5 The second expression is evaluated only if ... |
No credit card required