Language Reference - Operators

AutoIt has the following assignment, mathematical, comparison, and logical operators.

 

Operator Description

      Assignment operators
=
Assignment. e.g. $var = 5     (assigns the number 5 to $var)
+=
Addition assignment. e.g. $var += 1     (adds 1 to $var)
-=
Subtraction assignment.
*=
Multiplication assignment.
/=
Division assignment.
&=
Concatenation assignment.  e.g. $var = "one", and then $var &= 10    ($var now equals "one10")

      Mathematical operators
+ Adds two numbers.  e.g. 10 + 20    (equals 30)
- Subtracts two numbers.  e.g. 20 - 10    (equals 10)
* 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)

      Comparison operators (case insensitive if used with strings except for ==)
= Tests if two values are equal.  e.g. If $var= 5 Then    (true if $var equals 5). Case insensitive when used with strings.
== Tests if two strings are equal. Case sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used for string comparisons that need to be case sensitive.
<> Tests if two values are not equal. Case insensitive when used with strings. To do a case sensitive not equal comparison use Not ("string1" == "string2")
> Tests if the first value is greater than the second. Strings are compared lexicographically even if the contents of the string happen to be numeric.
>= Tests if the first value is greater than or equal to the second. Strings are compared lexicographically even if the contents of the string happen to be numeric.
< Tests if the first value is less than the second. Strings are compared lexicographically even if the contents of the string happen to be numeric.
<= Tests if the first value is less than or equal to the second. Strings are compared lexicographically even if the contents of the string happen to be numeric.

      Logical operators
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)
NOT Logical NOT operation.  e.g. NOT 1    (False)

 

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.


Note the following when using the logical operators AND, OR:

e.g. If  MyFunc1() OR MyFunc2() Then     (MyFunc2() is not called if MyFunc1() returns true)

e.g. If  MyFunc1() AND MyFunc2() Then    (MyFunc2() is not called if MyFunc1() returns false)