Break

Exits (terminates) any type of loop statement.

Break LoopLabel

Parameters

LoopLabel

If omitted or 1, this statement applies to the innermost loop in which it is enclosed. Otherwise, specify which loop this statement should apply to; either by label name or numeric nesting level. 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.

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

Examples

Breaks the loop if var is greater than 25.

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

Breaks 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.