Empty For Block

ID

kotlin.empty_for_block

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

empty, loop

Description

Reports for loops whose body is empty.

A for (item in collection) { } iterates over the range or collection but performs no work on each element, which is almost always a typo or the result of an incomplete refactoring where the body was accidentally removed.

Rationale

// Bad — empty body, no element processed
for (item in items) { }   // FLAW

// Bad — range iterated but nothing done
for (i in 0..10) { }   // FLAW

// Good — non-empty body
for (item in items) {
    process(item)
}

Remediation

Either fill in the missing body, or remove the for loop entirely if the iteration was no longer needed after a refactoring.