6. For Loops — A Book of Go

Louis Petrik
May 15, 2024
Source: the author

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
}

--

--