Captured Closure (for Loop Variable) in Go
Do you want the closure over the variable or the value? For example, package main import “fmt” func VariableLoop() { f := make([]func(), 3) for i := 0; i < 3; i++ { // closure over variable i f[i] = func() { fmt.Println(i) } } fmt.Println(“VariableLoop”) for _, f := range f { f() } … Read more