Non-local break & continue

Making inline lambdas truly first-class citizens

View at original site


We’re making a change to Kotlin that makes inline lambdas truly first-class language constructs, and makes them truly seamless to use. We do so by addressing a long-standing inconsistency when it comes to using break and continue inside lambdas.

In short: Kotlin becomes more consistent! And it does so by now experimentally supporting break and continue statements in a non-local manner, analog to nonlocal return expressions. This gets you more flexibility when you’re writing code where you have loops combined with inline functions that have lambda parameters – plus it finally makes inline lambdas real first-class language constructs.

This becomes super useful when you work with scope functions like let, apply, run, also, and with, when you work with mutexes or locks in Kotlin coroutines, or when you work with the Result type to do more functional error handling!

Related Resources

Your First AI Agent in Kotlin
Your First AI Agent in Kotlin
Get started with Koog today!
Exposed inline value classes for Java
Exposed inline value classes for Java
Use value classes from Java code with Kotlin 2.2
Nested type aliases in Kotlin 2.2
Nested type aliases in Kotlin 2.2
Use type aliases inside other structures