KT.LOOP_WITH_TOO_MANY_JUMP_STATEMENTS

Loops with multiple breaks or continue statements

Loops which contain multiple break or continue statements are hard to read and understand. To increase readability they should be refactored into simpler loops.

Noncompliant Code

Copy
val strs = listOf("foo, bar")
for (str in strs) {
    if (str == "bar") {
        break
    } else {
        continue
    }
}

Options

  • maxJumpCount (default: 1)

    maximum allowed jumps in a loop

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html