Less Than Or Equal To ( ≤ ) and Greater Than Or Equal To ( ≥ )

What is it?

The Less Than Or Equal To operator returns True if the first operand is of equal or lesser value than the second, and False otherwise. It has the exact opposite purpose to the Greater Than operator.

Similarly, the Greater Than Or Equal To operator returns True if the first operand is of equal or greater value than the second, and False otherwise. This operator has the exact opposite purpose to the Less Than operator.

What is the Syntax?

Less Than Or Equal To can be represented using the single character ≤. However, since most keyboards do not have this as a standard character, you may find it easier to use <= instead. This is a combination of the less than (<) and equals (=) operators, which is fitting due to this operator fulfilling a purpose which combines both of these.

Operand1 <= Operand2

The principle is much the same with Greater Than Or Equal To. The operator can be represented by the ≥ character, or >= if it is easier to use this notation instead.

Operand1 >= Operand2

Why might I want to use these operators?

We want to analyse a graph of water temperature over time in order to see when the water will have frozen or evaporated. We know that water evaporates at 100 degrees Celsius, and freezes at 0 degrees Celsius. Therefore, for each recorded temperature reading, we can apply logical operators to tell us when the water’s state will have changed.

The expression used each time we evaluate a value might look something like this:

if:( CurrentTemperature >= 100 )
{
WaterState := "Evaporated!"
}
else
{
if:( CurrentTemperature <= 0 )
{
WaterState := "Frozen!"
}
else
{
WaterState := "Liquid!"
}
}

This expression will first check if the value of CurrentTemperature is greater than or equal to 100, at which point it will assign the string value "Evaporated!" to WaterState.

If it's not, the expression will then check if CurrentTemperature is less than or equal to 0 and assign the value "Frozen!" to WaterState if it is.

Finally, if neither of these statements are correct - i.e. if the value of CurrentTemperature is between 1 and 99 - the expression will assign the value "Liquid!".

 

<< Previous: Less Than ( < ) and Greater Than ( > ) | Next: Comparing Strings >>