As of go1.24-cbdb3545ad, none of the following loops get optimized away:
package main
func main() {
for range 10 {
// Just an empty loop
}
var x int
for range 20 {
// x never gets read after the loop
x++
}
var y [30]int
for i := range y {
// The bounds check gets optimized out, turning this into an empty loop
_ = y[i]
}
for range "13 characters" {
// An empty loop that parses UTF-8
}
const debugFoo = false
const debugBar = false
for range 40 {
// Loop body is dead and gets optimized out
if debugFoo {
println()
}
if debugBar {
println()
}
}
}
As of
go1.24-cbdb3545ad
, none of the following loops get optimized away: