AutoIt (Operators)
From The Ultimate Programming Reference
(Difference between revisions)
Current revision as of 11:54, 26 March 2006
AutoIt has the following mathematical, logical and comparison operators.
Operator | Description |
---|---|
* | Multiplies two numbers. e.g. 20 * 10 (equals 200) |
/ | Divides two numbers. e.g. 20 / 10 (equals 2) |
& | Concatenates/joins two strings. e.g. "one" & 10 (equals "one10") |
^ | Raises a number to the power. e.g. 2 ^ 4 (equals 16) |
NOT | Logical NOT operation. e.g. NOT 1 (equals 0) |
= | Tests if two values are equal (case insensitive if used with strings). e.g. If $var= 5 Then (true if $var equals 5) |
== | Tests if two values are equal (case sensitive if used with strings) |
<> | Test if two values are not equal. |
> | Tests if the first value is greater than the second. |
>= | Tests if the first value is greater than or equal to the second. |
< | Tests if the first value is less than the second. |
<= | Tests if the first value is less than or equal to the second. |
AND | Logical AND operation. e.g. If $var = 5 AND $var2 > 6 Then (true if $var equals 5 and $var2 is greater than 6) |
OR | Logical OR operation. e.g. If $var = 5 OR $var2 > 6 Then (true if $var equals 5 or $var2 is greater than 6) |
When more than one operator is used in an expression the order in which things happen is controlled by operator precedence. The precedence used in AutoIt is given below. Where two operators have the same precedence the expression is evaluated left to right.
From highest precedence to lowest:
NOT ^ * / + - & < > <= >= = <> == AND OR
e.g. 2 + 4 * 10 is evaluated as 42:
4 * 10 (equals 40)
2 + 40 (equals 42)
As the * has a higher precedence than + it occurs before the addition.
You can use brackets to force a part of the expression to be evaluated first.
e.g. (2 + 4) * 10 equals 60.