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.

Example:

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) } }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

AmbiguousNonLocalJump
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Kotlin | Probable bugs

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Kotlin, 241.18072-IJ

Last modified: 18 June 2024