0Pricing
Kotlin Academy · Lesson

break, continue, and Labeled Returns

Control loop flow with break/continue and escape nested loops with labels.

Loop Flow Control

Kotlin supports break (exit the loop), continue (skip to next iteration), and labels for breaking out of nested loops.

break Basics

break exits the innermost enclosing loop immediately.

fun main() {
    for (i in 1..10) {
        if (i == 5) break
        print("$i ")
    }
    println() // 1 2 3 4
}

All lessons in this course

  1. for Loop Over Ranges and Collections
  2. while and do-while: When to Use Each
  3. forEach, repeat, and forEachIndexed
  4. break, continue, and Labeled Returns
← Back to Kotlin Academy