Go Conditional loop


Example

The for keyword is also used for conditional loops, traditionally while loops in other programming languages.

package main

import (
    "fmt"
)

func main() {
    i := 0
    for i < 3 { // Will repeat if condition is true
        i++
        fmt.Println(i)
    }
}

play it on playground

Will output:

1
2
3

infinite loop:

for {
    // This will run until a return or break.
}