Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The continue keyword in Kotlin is a structural jump expression that immediately terminates the execution of the current iteration within a loop (for, while, or do-while). Control flow is transferred directly to the loop’s next iteration phase, bypassing any remaining statements in the current loop body. Depending on the loop type, the exact control flow transfer behaves as follows:
  • for loop: Control jumps to the retrieval of the next element from the underlying iterator.
  • while and do-while loops: Control jumps directly to the evaluation of the loop’s boolean condition.
In Kotlin’s type system, continue evaluates to the Nothing type, signifying an expression that never completes normally.

Unlabeled continue

By default, an unqualified continue statement applies to the innermost enclosing loop.
for (i in 1..5) {
    if (i % 2 == 0) {
        continue 
    }
    println(i)
}

Labeled continue

Kotlin supports loop labeling, allowing developers to explicitly define the target loop for the jump expression. While frequently applied within nested loop architectures to bypass the innermost loop default, a labeled continue is syntactically valid on any labeled loop, including single, non-nested loops. A label is defined using an identifier followed by the @ symbol (e.g., target@). The continue expression invokes the label by appending the @ symbol and the identifier (e.g., continue@target).
outerLoop@ for (i in 1..5) {
    for (j in 1..5) {
        if (j == 3) {
            continue@outerLoop 
        }
        println("i = $i, j = $j")
    }
}

Lexical Scoping Constraints

The continue expression is strictly lexically scoped. It cannot be used to jump across function boundaries, including lambda expressions and anonymous objects. If a loop contains a higher-order function taking a lambda, a continue statement cannot be placed inside that lambda to affect the outer loop. Unlike the return keyword, which can perform non-local returns when used inside a lambda passed to an inline function, Kotlin does not support non-local continue (or break) statements under any circumstances. However, within the valid lexical scope of the loop, continue can be deeply nested inside any block or expression. Because continue evaluates to Nothing, it satisfies any type requirement. This allows it to be used idiomatically on the right-hand side of the Elvis operator (?:), within try-catch blocks, or inside deeply nested conditional statements, provided no function or lambda boundaries are crossed.
for (item in listOf("A", null, "B")) {
    // Valid use of continue nested within an expression
    val nonNullItem = item ?: continue
    
    try {
        if (nonNullItem == "Skip") {
            continue
        }
        println(nonNullItem)
    } catch (e: Exception) {
        continue
    }
}
Master Kotlin with Deep Grasping Methodology!Learn More