Introduction To Ruby
Comparison Operators
Comparison operators are used in Boolean expressions (expressions which evaluate to either true or false) when we want to test things in our programs.
Description | In Ruby |
---|---|
Equal to | == |
Less than | < |
Greater than | > |
Not equal to | != |
Less than or equal to | <= |
Greater than or equal to | >= |
In addition to the comparison operators, the boolean operators, NOT, AND, OR can also be used in boolean expressions.
! (num < 30) | num is not less than 30 |
num > 5 && num < 30 | num is greater than 5 and less than 30 |
num < 5 || num > 30 | num is less than 5 or num is greater than 30 |