Skip to content

single-iteration-loop

Default severity: warning

A loop whose top-level control flow always returns or breaks after a conditional branch cannot begin a second iteration. This usually means the exit was placed outside the intended branch.

Map ranges and one-statement loops are accepted because selecting a single arbitrary or first element is a common intentional pattern.

for _, value := range values { if done(value) { use(value) }; return }
for _, value := range values { if done(value) { break }; use(value) }