[go-nuts] why can't change map when in for range statements?

2018-01-15 Thread sheepbao
I wrote this code, and why `map=nil` don't stop the loop? ```go func mapTest() { m := map[int]int{1: 1, 2: 2} for k, v := range m { println(k, v) m = nil } } ``` output: 1 1 2 2 I don't understand when I set `m = nil`, the loop is not stop. m doesn't seem

Re: [go-nuts] why can't change map when in for range statements?

2018-01-16 Thread Marvin Renich
* sheepbao [180115 21:24]: > I wrote this code, and why `map=nil` don't stop the loop? > > func mapTest() { > for k, v := range m { > println(k, v) > m = nil > } > } > > output: > > 1 1 > > 2 2 > > I don't understand when I set `m = nil`, the loop is not stop. m doesn