Less Than ( < ) and Greater Than ( > )
What is it?
Less Than and Greater Than are two distinct but similar operators designed to test whether or not one operand is less than or greater than another, respectively.
Less Than returns True if the first operand is numerically lower than the second, and False if it is equal to or greater than it.
Similarly, Greater Than returns True if the first operand is numerically higher than the second, and False if it is equal to or less than it.
What is the Syntax?
The Less Than operator’s syntax is as follows:
Operand1 < Operand2
Whereas the Greater Than operator’s syntax is:
Operand1 > Operand2
Why might I want to use these operators?
There are a great number of real-world examples that you can use the above two operators to evaluate:
Less Than
During a certain election campaign there are three rounds of voting, with all candidates who do not obtain enough votes to stay in the running removed from contention at the end of each round. The minimum number of votes to stay in the election (MinVotes) is calculated when the total number of votes are known, then used to assess each candidate’s performance (VotesReceived).
When the value of MinVotes for a given round has been established, we use the following expression to decide whether or not a candidate is to be removed from contention:
if:( VotesReceived < MinVotes )
{
"Candidate has been eliminated"
}
Any candidate with fewer VotesReceived than the MinVotes limit is eliminated from the election at the end of the round.
Greater Than
Airline passengers are given weight limits for all carry-on luggage, to ensure anything too heavy to safely store in the overhead lockers is moved to the aircraft’s hold. This expression checks the weight of each bag passed through customs to ensure that commuters have not exceeded the weight limit:
if:( BagWeight > 25 )
{
"Passenger asked to remove items from bag or stow it in aircraft hold"
}
else
{
"Passenger free to take luggage as carry-on"
}
Here, any bag weighing more than 25kg is not permitted for carry-on luggage, and will need to be stowed in the aircraft’s hold.
<< Previous: Not Equal ( < > ) | Next: Less Than Or Equal To ( ≤ ) and Greater Than Or Equal To ( ≥ ) >>