Else

Specifies one or more statements to execute if an If statement evaluates to false.

Else Statement
Else
{
    Statements
}

Remarks

Every use of an Else must belong to (be associated with) an If statement above it. An Else always belongs to the nearest unclaimed If statement above it unless a block is used to change that behavior.

An Else can be followed immediately by any other single statement on the same line. This is most often used for "else if" ladders (see examples at the bottom).

If more than one statement is specified to be executed, those statements must be enclosed in braces (to create a block). Otherwise, the braces are optional. For example:

if (count > 0)  ; No braces are required around the next line because it's only a single line.
    MsgBox Press OK to begin the process.
else  ; Braces must be used around the section below because it consists of more than one line.
{
    WinClose Untitled - Notepad
    MsgBox There are no items present.
}

The One True Brace (OTB) style may optionally be used around an Else. For example:

if IsDone {
    ; ...
} else if (x < y) {
    ; ...
} else {
    ; ...
}

Related

Blocks, If Statements, Control Flow Statements

Examples

#1

if WinExist("Untitled - Notepad")
{
    WinActivate
    Send This is a test.{Enter}
}
else
{
    WinActivate, Some Other Window
    MouseClick, Left, 100, 200
}

if (x = 1)
    Gosub, a1
else if (x = 2) ; "else if" style
    Gosub, a2
else IfEqual, x, 3 ; alternate style
{
    Gosub, a3
    Sleep, 1
}
else Gosub, a4  ; i.e. Any single statement can be on the same line with an Else.
 
; Also OK:
IfEqual, y, 1, Gosub, b1
else {
    Sleep, 1
    Gosub, b2
}