Comparison Operators
Comparison operators are used to compare two things, typically numbers (integers or floats)
Try these in IRB!
5 == 4
=> false
5 != 4
=> true
1 < 2
=> true
Try these in IRB!
1 > 2
=> false
7.1 <= 7.2
=> true
7.1 >= 7.2
=> false
expression1 operator expression2
my_string.length > maximum_length
Note: Expressions can contain variables and method calls, as we have seen before
trueor
false
== | Are the left and right side equal? |
!= | Are the left and right side not equal? |
< | Is the left side smaller than the right side? |
> | Is the left side bigger than the right side? |
<= | Is the left side smaller than or equal to the right side? |
>= | Is the left side bigger than or equal to the right side? |
What questions do you have?