How to Loop Forever in Golang


If you need to loop forever, or infinitely, in your Go code, then you have 2 options:

Option 1:

for {
  // your code here
}

Option 2:

for true {
  // your code here
}

Just remember that you need to break out of this, otherwise it really will run forever!

How to use in a Go Application

package main

func main() {

  // OPTION 1
  for {
    // your code here
  }

  // OPTION 2
  for true {
    // your code here
  }

}