package main
func main() {
for { // L4
}
for {
continue
}
for false { // L10
}
for false {
continue
}
}
$ staticcheck main.go
main.go:4:2: this loop will spin, using 100% CPU (SA5002)
main.go:10:2: loop condition never changes or has a race condition (SA5002)
main.go:10:2: this loop will spin, using 100% CPU (SA5002)
main.go:10:2: this loop will spin, using 100% CPU
Is a bug that we should fix, though not a high priority one.
That we don't detect for { continue } is acceptable. We don't strive to find all bugs. There are an infinite number of programs that spin without doing any useful work, but only for {} is commonly used by beginners. It isn't worth making the check vastly more complex to catch artificial bugs.
Most helpful comment
Is a bug that we should fix, though not a high priority one.
That we don't detect
for { continue }is acceptable. We don't strive to find all bugs. There are an infinite number of programs that spin without doing any useful work, but onlyfor {}is commonly used by beginners. It isn't worth making the check vastly more complex to catch artificial bugs.