https://golang.org/ref/spec#For_range个
带有"range"子句的"for"语句遍历所有条目 通道上接收的数组、切片、字符串或映射或值的. 对于每个条目,它将迭代值分配给相应的迭代 变量,然后执行挡路.
例如:
for index, element := range someSlice {
// index is the index where we are
// element is the element from someSlice for where we are
}
如果您不关心索引,可以使用_
:
for _, element := range someSlice {
// element is the element from someSlice for where we are
}
下划线_
是blank identifier,这是一个匿名占位符.