Relational Operators


These operators are used to check for relations like equality, greater than, less than. They return boolean result after the comparison and are extensively used in looping statements as well as conditional if else statements

==       Equal to   (  x == y) 

!=        Not equal   (  x != y  )

>         Greater than  (    x > y   ) 

<         Less than   (  x < y   ) 

>=       Greater than or equal to ( x >= y )

<=       Less than or equal to  (   x <= y)

Logical Operators:

 These operators are used to perform “logical AND” and “logical OR” operation, i.e. the function similar to AND gate and OR gate in digital electronics. One thing to keep in mind is the second condition is not evaluated if the first one is false, i.e. it has a short-circuiting effect. Used extensively to test for several conditions for making a decision.

 

 

Examples:

&&     Logical and   Returns true if both statements are true.  

Ex.      (x < 5 &&  x < 10)      

||        Logical or  Returns true if one of the statements is true .

Ex.      (x < 5 || x < 4 )   

 !        Logical not  Reverse the result, returns false if the result is true.

Ex.      !(x < 5 && x < 10)