A for loop executes a block of code repeatedly, and in Golang, there are several different ways to write one.

  1. The standard three-component loop
  2. For-range loop
    1. Range over slice
    2. Range over map
    3. Range over channel
    4. Range over string
  3. While loop
  4. Optional components loop
  5. Infinite loop
  6. Break from a loop
  7. Continue (skip to the next iteration) in a loop

#golang #mailing-list

All the Ways to Write for Loops in Go
1.30 GEEK