TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
break expression in Kotlin is a structural jump control flow operator used to prematurely terminate the execution of an enclosing loop (for, while, or do-while). Upon execution, control is immediately transferred to the statement directly following the terminated loop. Because it unconditionally alters control flow, the expression evaluates to the Nothing type.
Kotlin supports two forms of the break expression: unlabeled and labeled.
Unlabeled Break
An unlabeledbreak terminates the nearest (innermost) enclosing loop in the lexical scope.
Labeled Break
A labeledbreak is used to terminate a specific loop within a nested loop structure. A label in Kotlin is defined by an identifier followed by an @ sign (e.g., outer@). The break expression is then appended with the same label (break@outer).
When a labeled break is invoked, execution jumps to the statement immediately following the loop designated by that label.
Technical Constraints and Mechanics
- Lexical Scope: The
breakexpression must be lexically enclosed by the loop it intends to terminate. It will result in a compiler error if used outside of a loop construct. - Lambda Expressions:
breakis not supported inside lambda expressions passed to higher-order functions (such asIterable.forEach). To achieve early termination in those contexts, structural loops or labeledreturnexpressions must be used instead. - Type System Integration: Because
breakevaluates toNothing, it acts as a bottom type. This means it can be used as a branch in expressions where a specific type is expected, provided thebreakitself remains lexically scoped within a loop. The compiler allows this because it guarantees the assignment or subsequent evaluation will never be reached.
Master Kotlin with Deep Grasping Methodology!Learn More





