i:=i
golang 官方Effective GOreqreq := req
https://golang.org/doc/effective_go#concurrency
req := reqEffective GO
req
直接这么看,还是有点拗口。不过不重要, 在了解了 golang 的 区块(block) 定义范围之后, 就迎刃而解了。
Blocks
https://golang.org/ref/spec#Blocks
block
Blocks
{}
Block 的范围在哪里?
{}
universe
The universe block encompasses all Go source text.
universe
package
Each package has a package block containing all Go source text for that package.
packagepackagepackage.Variable
file
Each file has a file block containing all Go source text in that file.
block
目前发现现象,
filename_test.gofilename.go
file block
_test
main_test.gomain.gomain.goVarInTest
forifswitch
Each “if”, “for”, and “switch” statement is considered to be in its own implicit block.
forifswitch{}
{}for block(statement block)
i:=istatement block同名变量覆盖
也就是因为 {} 是 for 子block 的原因, for 的 post 可以修改变量 i, 在 statement 中也可以修改变量 i
loop: 0,1,2,9for blockistatement block_iif blockstatement block_ifor blockiloop: 0-9
switch / selectclause
Each clause in a “switch” or “select” statement acts as an implicit block.
switch / selectcase / default:
func blockiswitch clause 分支{