KT.UNCONDITIONAL_JUMP_STATEMENT_IN_LOOP

Loops contains jump statements that jump regardless of any conditions

Reports loops which contain jump statements that jump regardless of any conditions. This implies that the loop is only executed once and thus could be rewritten without a loop altogether.

Noncompliant Code

Copy
for (i in 1..2) break

Compliant Code

Copy
for (i in 1..2) {
    if (i == 1) break
}

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