The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
whoami9894

issue about `go range`

  •  
  •   whoami9894 · Jun 24, 2019 · 2273 views
    This topic created in 2543 days ago, the information mentioned may be changed or developed.
    func main() {
        f := map[string]interface{}{
            "a": "a",
        }
    
        for _, v := range f {
            v := v.(string)
        }
    
        w := f["a"]
        w := w.(string)
    }
    
    // .\test.go:13:7: no new variables on left side of :=
    

    range 迭代时v := v.(string)scope 里已经存在一个 v 变量,为什么可以定义同名新变量呢

    whoami9894
        1
    whoami9894  
    OP
       Jun 24, 2019 via Android
    明白了。。。md 脑子抽了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:28 · PVG 06:28 · LAX 15:28 · JFK 18:28
    ♥ Do have faith in what you're doing.