For is the only loop in Go.
- 3 parts as usual in Go:
- init statement
- condition expression
- post statement
- But no ( ) surrounding the statements
- The init and post statements are optional:
sum := 1
for ; sum < 1000; {
sum += sum
}Using for as while
Instead of using whileone can use foralmost in the same way:
for sum < 1000 {
}Infinite loops
for {
}Next Chapter: Arrays and slices