Gaaker Go

Golang Infinite loop

The for conditional expression can be omitted, for example:

for {

}

A for loop without a conditional expression is essentially an infinite loop.

The following is a complete code example.

package main

import (
    "fmt"
    "time"
)

func main() {
    i := 0
    for {
        fmt.Println(i)
        i++
        time.Sleep(time.Second * 1)
    }
}

Below is the program output:

0
1
2
3
.
.
.
< Infinite loop Infinite loop >