Continue

Skips the rest of a loop statement's current iteration and begins a new one.

Continue 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: continue("outer")

Remarks

Continue behaves the same as reaching the loop's closing brace:

  1. It increases A_Index by 1.
  2. It skips the rest of the loop's body.
  3. The loop's condition (if it has one) is checked to see if it is satisified. If so, a new iteration begins; otherwise the loop ends.

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

Related

Break, Loop, Until, While-loop, For-loop, Blocks, Labels

Examples

#1: This example displays 5 message boxes, one for each number between 6 and 10. Note that in the first 5 iterations of the loop, the Continue statement causes the loop to start over before it reaches the MsgBox line.

Loop 10
{
    if (A_Index <= 5)
        continue
    MsgBox A_Index
}

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

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