Comparison Operators: Greater than and Less than
Another common comparison operator is the greater than >
and less than <
operators. These operators are used to compare two values to see if one is greater than or less than the other. For example:
Let's see a very simple example where we can use these operators:
In this example, we are comparing the value of the age
variable to the number 18
. Since 10
is less than 18
, the value of isKid
is true
.
There are also greater than or equal to >=
and less than or equal to <=
operators.
These operators are similar to the greater than >
and less than <
operators, but they also include the case where the two values being compared are equal.
The >=
operator means greater than or equal to
. It is used to compare two values and returns true if the left value is greater than or equal to the right value, and false otherwise.
The <=
operator means less than or equal to
. It is used to compare two values and returns true if the left value is less than or equal to the right value, and false otherwise.
Here's an example:
In this example, we are comparing the value of the age
variable to the number 18
. Since 18
is greater than or equal to 18
, the value of isAdult
is true
.
In the code below we have two variables (a
and b
).
Fill in the spaces indicated with the required operations.