go的变量作用域
if, for等可以有初始化表达式的,其作用域还要高于其后的花括号一层
package main func main() { x:=1 println(x) for x:=3;;{ print(x," ") break } println(x) if x:=5; true { print(x," ") } println(x) for { x:=7 print(x," ") break } println(x) if true { x:=9 print(x," ") } println(x) if x:=2; true { print(x," ") x:="abc" print(x," ") } println(x) for x:=4;; { print(x," ") x:="def" print(x," ") break } println(x) } // 1 // 3 1 // 5 1 // 7 1 // 9 1 // 2 abc 1 // 4 def 1
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。