Skip to content

single-iteration-loop

Detect loops that always exit during their first iteration.

Updated View as Markdown

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.

Bad

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

Good

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

Type to search…

↑↓ navigate↵ selectEsc close