Next freebie in 28 Hours*
We have seen the use of the equality operator and how it is different from the assignment operator. Similarly, Rational Operators also compare two variables and give the result as a Boolean value (true or false.) For Rational Operators we use angular braces or you can say angle brackets or even corner braces. However, we usually to refer them as "greater than symbol >" and "less than symbol <." Likely you now understand what type of symbols we are referring to. We use the same > and < which we used in mathematics in our primary school. In addition there are also two more rational operators which are formed by combining these symbols with the = sign. They are >= and <=, referred as 'greater than or equal to' and 'less than or equal to' respectively.
We use this operator to compare the two values or variables to check if one is greater than the other or not. The result is shown in Boolean values. For example, if we consider trace(a>b), the result will be true if 'a' is greater than 'b' and false if 'a' is either less than or equal to 'b'. One more example: trace(7>3), since 7 is greater than 3, the output is given as true. For trace(3>7), the output would be false.
This is same logic as the one above but reversed. The compiler here checks whether one value is less than the other or not. For example, if we take trace(a<b). the result is true if the value of a is less than b and false if it is equal to or greater than b. If we consider trace(6<7) and trace(5<3), the result is true for the first one and false for the second one.
We have seen how to compare and find whether the first value is less than the second value or greater than the second value. There are cases where we need to find whether the first value is either 'greater than or equal to' to the second value or not. In such a case we use the symbol >=. Similarly, to check if the first value is either 'smaller than or equal to' the second value, we use the symbol <= for that comparison. For example if we take trace(6>=5), the result would be true which meets the greater than condition. If we consider trace(6>=6), the result is still same (true) because it meets the equality condition. Same is the case for trace(5<=6) and trace(6<=6), the result is true for both.
Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.