You can see your error if you initialise i to -1 before the loop: v[i]
is evaluated before i is incremented.

On Wed, 6 Dec 2017, at 02:26 PM, T L wrote:
> 
> package main
> 
> import "fmt"
> 
> func main() {
>   var i int
>   var x = []int{3, 5, 7}
>   var y = make([]int, 3)
>   for i, y[i] = range x {
>       fmt.Println(i, ":", y, ", y[", i, "] =", y[i])
>   }
>   fmt.Println("y =", y)
> }
> 
> // output:
> 0 : [3 0 0] , y[ 0 ] = 3
> 1 : [5 0 0] , y[ 1 ] = 0
> 2 : [5 7 0] , y[ 2 ] = 0
> y = [5 7 0]
> 


> --
>  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.

-- 
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