The for loop has three components, and can be used just like a for loop in C or Java. Go has no while loop because the for loop serves the same purpose when used with a single condition. Refer to the following example for more clarity:
package main
import ( "fmt" )
func main() { // Basic for loop for i := 0; i < 3; i++ { fmt.Println("i:", i) }
// For used as a while loop n := 5 for n < 10 { fmt.Println(n) n++ } }