If / IfEqual / IfNotEqual / IfLess / IfLessOrEqual / IfGreater / IfGreaterOrEqual

Specifies the command(s) to perform if the comparison of a variable to a value evalutes to TRUE. When more than one command is present, enclose them in a block (braces).

IfEqual, Var, Value (same: if Var = Value)
IfNotEqual, Var, Value (same: if Var <> Value) (!= can be used in place of <>)
IfGreater, Var, Value (same: if Var > Value)
IfGreaterOrEqual, Var, Value (same: if Var >= Value)
IfLess, Var, Value (same: if Var < Value)
IfLessOrEqual, Var, Value (same: if Var <= Value)
If Var ; If Var's contents are blank or 0, it is considered false. Otherwise, it is true.

See also: IfInString



The variable name.


A literal string, number, or variable reference (e.g. %var2%). Value can be omitted if you wish to compare Var to an empty string (blank).


If both Var and Value are purely numeric, they will be compared as numbers rather than as strings. Otherwise, they will be compared alphabetically as strings (that is, alphabetical order will determine whether Var is greater, equal, or less than Value).

When an IF or an ELSE owns more than one line, those lines must be enclosed in braces. For example:

if count <= 0
    WinClose Untitled - Notepad
    MsgBox There are no items present.

However, if only one line belongs to the IF or ELSE, the braces are optional.

Another command can only appear on the same line as the IF statement if you use the command-name style. In other words, these are valid:

IfEqual, x, 1, Sleep, 1
IfGreater, x, 1, EnvAdd, x, 2

But these are not valid:

if x = 1 Sleep 1
IfGreater, x, 1, x += 2

The One True Brace (OTB) style may not be used with these types of if-statements. It can only be used with expression if-statements.

On a related note, the command if var [not] between LowerBound and UpperBound checks whether a variable is between two values, and if var [not] in value1,value2 can be used to check whether a variable's contents exist within a list of values.


IF (expression), StringCaseSense, Assign expression (:=), if var in/contains MatchList, if var between, IfInString, Blocks, Else


if counter >= 1
    Sleep, 10

if counter >=1   ; If an IF has more than one line, enclose those lines in braces:
    WinClose, Untitled - Notepad
    Sleep 10

if MyVar = %MyVar2%
    MsgBox The contents of MyVar and MyVar2 are identical.
else if MyVar =
    MsgBox, 4,, MyVar is empty/blank. Continue?
    IfMsgBox, No
else if MyVar <> ,
    MsgBox The value in MyVar is not a comma.
    MsgBox The value in MyVar is a comma.

if Done
    MsgBox The variable Done is neither empty nor zero.