# 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

### Parameters

var | The variable name.
value | 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).

### Remarks

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.

### Related

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

### Example

    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
            Return
    }
    else if MyVar <> ,
        MsgBox The value in MyVar is not a comma.
    else
        MsgBox The value in MyVar is a comma.

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