6. For Loops — A Book of Go
May 15, 2024
For is the only loop in Go.
It consists of parts as usual in programming languages:
- 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
}