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 }
Code language: Go (go)

Option 2:

for true { // your code here }
Code language: Go (go)

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 } }
Code language: Go (go)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments