Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Logical Operators

 

Logical operators are used in order to group boolean values or boolean expressions together and make decisions based on, if all of them, one of them  or none is true.

There are 3 Logical operators and all of them return boolean values:

The AND  operator: &&. That checks if both conditions are true and evaluates to true. If only one of the conditions that are being checked is false then the whole logical operation evaluates to false. For example i am going to buy myself an ice cream ONLY when i have enough money for it (so the money in my wallet is bigger number than the price of the ice cream) AND if the temperature is more than 25 degrees! If one of these conditions evaluate to false then the whole condition is false. BOTH have to be true in order to buy the ice cream. We group this condition with the AND (&&) operator.

The OR operator: ||. Checks if one condition of the group is true. If so it evaluates the whole operation to true. Either the one or the other one is enough to evaluate to true.

The NOT operator:  ! Checks if something is not true. (see comparison operators also).