For
The Go for
loop has three forms, only one of which hassemicolons:
for init; condition; post { }
- a loop using the syntax borrowed from C;for condition { }
- a while loop, and;for { }
- an endless loop.
Short declarations make it easy to declare the index variable right in the loop.
sum := 0
for i := 0; i < 10; i++ {
sum = sum + i
}
Note that the variable i
ceases to exist after the loop.
当前内容版权归 Miek Gieben 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Miek Gieben .