Saturday 31 December 2011

Logical Operators

  •  && ( logical AND )
    •  Returns true if both conditions are true
  •  || ( logical OR )
    •  Returns true if either of its conditions are true
  •  ! ( logical NOT, logical negation )
    •  Reverses the truth/falsity of its condition
    •  Unary operator, has one operand
  •  Useful as conditions in loops
     Expression                Result
     true && false             false
     true || false             true
     !false                    true




Truth table for the && (logical AND) operator.


Truth table for the logical OR (||) operator.


Truth table for operator ! (logical negation).


Operator Precedence and Associativity





No comments:

Post a Comment