On Thu, Feb 23, 2017 at 8:59 AM, Victor Kovacs <[email protected]> wrote:
>
> // 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.
>
>
This is a variant of https://golang.org/doc/faq#closures_and_goroutines

Your function literal captures a reference to the variables 'i' and 'j',
These variables are modified by the loop on the next iteration.

The reason for using i := i is to copy the value from the loop variable 'i'
in to a new variable also called 'i', which won't be modified by the next
iteration of the loop.

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to