Inspectopedia Help

Ambiguous non-local 'break' or 'continue'

Reports break or continue usages inside of lambdas of loop-like functions.

break and continue keywords always apply to the real loops (for, while, do-while). break and continue never apply to any function; for example, break and continue don't apply to forEach, filter, map.

Using break or continue inside a loop-like function (for example, forEach) may be confusing. The inspection suggests adding a label to clarify to which statement break or continue applies to.

Since Kotlin doesn't have a concept of loop-like functions, the inspection uses the heuristic. It assumes that functions that don't have one of callsInPlace(EXACTLY_ONCE) or callsInPlace(AT_LEAST_ONCE) contracts are loop-like functions.


for (file in files) { file.readLines().forEach { line -> if (line == commentMarkerLine) continue println(line) } }

The quick-fix adds clarifying labels:

loop@ for (file in files) { file.readLines().forEach { line -> if (line == commentMarkerLine) continue@loop println(line) } }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Kotlin, @snapshot@

Last modified: 13 July 2023