基本循环
for
是 go 中唯一的循环语句,因此基本循环实现可能如下所示:
// like if, for doesn't use parens either.
// variables declared in for and if are local to their scope.
for x := 0; x < 3; x++ { // ++ is a statement.
fmt.Println("iteration", x)
}
// would print:
// iteration 0
// iteration 1
// iteration 2