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

Specifies one or more statements to execute if the comparison of a variable to a value evaluates to true.

Deprecated: Legacy If statements are not recommended for use in new scripts. See Scripting Language: If Statement for details and use If (expression) instead.

IfEqual, Var , Value          ; if Var = Value
IfNotEqual, Var , Value       ; if Var != Value
IfLess, Var , Value           ; if Var < Value
IfLessOrEqual, Var , Value    ; if Var <= Value
IfGreater, Var , Value        ; if Var > Value
IfGreaterOrEqual, Var , Value ; if Var >= Value


The name of a variable. Percent signs must be omitted except when attempting a double reference. Unlike the input variables of other commands, the percent prefix is not supported.
Unquoted text or a number. Variable references must be enclosed in percent signs (e.g. %var2%). Value can be omitted if you wish to compare Var to an empty string (blank).


변수(Var)와 값(Value)이 순수하게 숫치라면, 문자열이 아니라 숫자로 비교됩니다. 그렇지 않으면, 문자열로 알파벳 순으로 비교됩니다 (즉, 알파벳 숫서로 VarValue보다 큰지 작은지 같은지 결정합니다).

If an If owns more than one line, those lines must be enclosed in braces (to create a block). 그렇지만, 한 줄만 IF 또는 If에 속해 있다면, 활괄호는 선택적입니다. 예를 들어:

if count <= 0
    WinClose Untitled - Notepad
    MsgBox 항목이 하나도 없습니다.

Note that command-like If statements allow a command or command-like control flow statement to be written on the same line, but mispelled command names are treated as literal text. 다른 말로, 다음은 유효합니다:

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

그러나 다음은 유효하지 않습니다:

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

The One True Brace (OTB) style may not be used with legacy If statements. It can only be used with If (expression).

On a related note, the statement if Var between LowerBound and UpperBound checks whether a variable is between two values, and if Var in MatchList can be used to check whether a variable's contents exist within a list of values.

If (expression), StringCaseSense, 할당 표현식 (:=), if var in/contains MatchList, if var between, IfInString, 블록, Else


If counter is greater than or equal to 1, sleep for 10 ms.

if counter >= 1
    Sleep, 10

If counter is greater than or equal to 1, close Notepad and sleep for 10 ms.

if counter >= 1   ; For executing more than one line, enclose those lines in braces:
    WinClose, Untitled - Notepad
    Sleep 10

This example is executed as follows:

  1. If MyVar is equal to MyVar2, show "The contents of MyVar and MyVar2 are identical."
  2. Otherwise if MyVar is empty:
    1. Show "MyVar is empty/blank. Continue?" and wait for user input.
    2. If the user presses "No", stop further checks.
  3. Otherwise if MyVar is not a comma, show "The value in MyVar is not a comma.".
  4. Otherwise show "The value in MyVar is a comma.".
if MyVar = %MyVar2%
    MsgBox MyVar와 MyVar2의 내용은 동일합니다.
else if MyVar =
    MsgBox, 4,, MyVar가 비어 있습니다. 계속할까요?
    IfMsgBox, No
else if MyVar != ,
    MsgBox MyVar의 값은 쉼표가 아닙니다.
    MsgBox MyVar의 값은 쉼표입니다.

If Done is neither empty nor zero, show "The variable Done is neither empty nor zero.".

if Done
    MsgBox 변수 Done은 비어 있지도 않고 0도 아닙니다.