Hi, I've recently started learning go as a way to learn mobile apps and have started experimenting with flappy from the mobile examples (https://github.com/golang/mobile/tree/master/example/flappy) While doing some changes I've run into a problem that I don't understand. The code :
for i :=0; i <2; i++{ > for j :=0; j<2 ; j++{ > newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { > fmt.Println(i, j) produces this error with i and j being 2 : panic: runtime error: index out of range > The example code https://github.com/golang/mobile/tree/master/example/flappy solves this by assigning i again inside the loop-block : starting ligne 96 : > > newNode := func(fn arrangerFunc) { > n := &sprite.Node{Arranger: arrangerFunc(fn)} > eng.Register(n) > scene.AppendChild(n) > } > > // The ground. > for i := range g.groundY { > i := i > // The top of the ground. > newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { > While this solves the issue I would like to understand what is happening. Any insight is appreciated. Thanks for your help, Victor -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.