← Back to archive

Stdle #71 · iteration · 2026-08-16

What does this Go snippet output?

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

package main
import "fmt"
func main() {
results := []int{}
for i := range 3 {
func() {
defer func() { results = append(results, i) }()
}()
}
fmt.Println(results)
}
Iteration
4 attempts left

Answer & explanation