基本迴圈

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