What Is A Comparision Operator

Updated: January 25, 2022
No Credit Card Required


Every day people need to make decisions. Usually they come to decisions through comparisons, they choose the option that seems to give the best outcome. For example, when comparing smartphones, one phone might have a bigger screen, but another model might have more storage space, and yet another model might have longer battery life. When confronted with a decision like this, we need to work out what the better option is, we also need to figure out the worst option and if some options will have the same outcome.

In programming, this process is called logical comparison, and better refers to greater, worse refers to lesser and the same refers to equal. Most people compare options, computers and robots compare values to decide between one or more options. To decide between two options, a computer program uses a conditional statement.

For example, many factories use robots to test for quality, the robots perform certain actions based on different conditions. In this factory, robots are testing mobile phones for quality. If the phone scores 90 or better on the quality test, then the robot places it in the box for shipping. If the phone scores less than 90, then the robot sends it to the reject pile. So the robot makes a decision on which action to perform, putting it in a box or putting it on the reject pile based on the test score.

The program instructions to the robot are if the test score is 90 or above then placed the phone in a box or else rejected. The way the robot makes this decision is to compare the value from the test score with a second value, a passing score for quality. This second value is called a condition. If the test score is equal to 90 or greater than 90, that condition is said to be true, and the program instructs the robot to put the phone in a box. If the test score is 89 or lower, the condition is said to be false, and the program instructs the robot to reject the phone.

We can write this as a simple formula. If the test score equals greater than 90, then put the phone in a box for review.. This is called an “if then else” conditional statement. And we use it as we program to help the robot make the right decision. Pretty cool huh? Conditional statements are important in programming. They are the deciding factor on if and when a specific action will be carried out. Humans also make decisions in a similar way. Although they might be unaware of it much of the time. Comparison is what people computers and robots use to make a decision. Some choose better than others.