Gaaker Go

Golang While loop

There is no while loop in Go.

But a for loop with only conditional expressions is equivalent to a while loop.

The following is a complete code example.

package main

import "fmt"

func main() {
	sum := 1
	for sum < 1000 {
		sum += sum
	}
	fmt.Println(sum)
}

Below is the program output:

1024
< While loop While loop >