18.4.7 Comparison operators
The binary comparison operator compares the first operand with the second operand to verify that the specified relationship is valid. If the comparison expression evaluates to true, 1 is returned. If the comparison expression evaluates to false, 0 is returned. The result is the bool type.
- Organization of this subsection
(1) Format
- Comparison expression
expression < expression expression > expression expression <= expression expression >= expression
- Equality
expression == expression
- Inequality
expression != expression
(2) Description
The following gives the relationships checked by the comparison operator.
Operator |
Relation to be checked |
---|---|
< |
The first operand is smaller than the second operand. |
> |
The first operand is greater than the second operand. |
<= |
The first operand is equal to or smaller than the second operand. |
>= |
The first operand is equal to or greater than the second operand. |
== |
The first operand is equal to the second operand. |
!= |
The first operand is not equal to the second operand. |
You can specify an operand of type integer, float, or string. You may specify operands of different types. Comparison operators perform normal arithmetic conversion for operands of integer and float types. You can also use a combination of some operand types, and the comparison or equal operator.
The following table shows how the comparison operators evaluate the comparison results as true or false.
Operator |
Meaning |
True |
False |
---|---|---|---|
< |
Smaller than |
expression-1 < expression-2 |
expression-1 >= expression-2 |
> |
Greater than |
expression-1 > expression-2 |
expression-1 <= expression-2 |
<= |
Equal to or smaller than |
expression-1 <= expression-2 |
expression-1 > expression-2 |
>= |
Equal to or greater than |
expression-1 >= expression-2 |
expression-1 < expression-2 |
== |
Equal to |
expression-1 == expression-2 |
expression-1 != expression-2 |
!= |
Not equal to |
expression-1 != expression-2 |
expression-1 == expression-2 |
The following table gives the results of comparison expressions depending on the data types of expressions.
Data types of expressions |
Operation |
---|---|
Both expressions are numeric. |
Compares the numeric values. |
Both expressions are string type. |
Compares the character strings. |
One expression is numeric and the other expression is string type. |
Results in an error. |
(3) Example of coding
if (sloop_cnt < (sloop_max - 25)) // < AIT_LogMessage("Searching for Active windows"); //Search Active windows if (AIT_FocusWindow("Installable Software Extracting...", "#32770",0.0) > 0) // > AIT_LogMessage("Installable Software Extracting... is opened"); sloop_cnt= 0; endif; endif;