← Back to archive

Stdle #98 · defer · 2026-09-12

What does this Go snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

package main
import "fmt"
func f() (result int) {
for i := 0; i < 3; i++ {
defer func() { result += i }()
}
return 0
}
func main() {
fmt.Println(f())
}
Defer
4 attempts left

Answer & explanation