♾️ Infinite loop in Go

introduction loop

To define an infinite loop in Go, also known as a “while true” loop in many different languages, you need to use the for statement. The traditional for loop has the form of:

for initialization; condition; post-condition {
...
}
but when you omit the initialization, condition, and post-condition statements, you get the classic “while true” infinite loop:
for {
...
}

There is no while keyword in Go, so all “while” loops can be created with the for keyword.

Example:

package main

import (
    "fmt"
    "time"
)

func main() {
    for {
        fmt.Println("https://gosamples.dev is the best")
        time.Sleep(1 * time.Second)
    }
}

💤 While loop in Golang

Learn how to construct the popular programming while loop
introduction loop

➰ Foreach loop in Go

Learn how to construct the popular programming loop
introduction loop

📔 Convert a struct to io.Reader in Go

Learn how to convert a struct to io.Reader and send it as an HTTP POST request body
introduction http