Break

Exits (terminates) any type of loop statement.

Break LoopLabel

Parameters

LoopLabel

LoopLabel identifies which loop this statement should apply to; either by label name or numeric nesting level. If omitted or 1, this statement applies to the innermost loop in which it is enclosed. If a label is specified, it must point directly at a loop statement.

LoopLabel must be a constant value - variables and expressions are not supported, with the exception of a single literal number or quoted string enclosed in parentheses. For example: break("outer")

Remarks

The use of Break and Continue are encouraged over Goto since they usually make scripts more readable and maintainable.

Related

Continue, Loop, While-loop, For-loop, Blocks, Labels

Examples

#1

Loop
{
    ; ...
    if (var > 25)
        break
    ; ...
    if (var <= 5)
        continue
}

#2: Break the outer loop from within a nested loop.

outer:
Loop 3
{
    x := A_Index
    Loop 3
    {
        if (x*A_Index = 6)
            break outer  ; Equivalent to break 2 or goto break_outer.
        MsgBox x "," A_Index
    }
}
break_outer: ; For goto.