Skip to content

Instantly share code, notes, and snippets.

@jochasinga jochasinga/loop.go
Created Sep 30, 2014

Embed
What would you like to do?
Loops in Go
package main
import "fmt"
func main() {
loops := 1
// while loop
for loops < 10 {
fmt.Println(loops)
loops++
}
// for loop
for i := 0 ; i < loops ; i++ {
fmt.Println(i)
}
// Infinite loop
for {
// something to run forever
}
// C-style while loop
j := 0
for ; j < 10 ; {
fmt.Println(string(10))
}
// C-style infinite loop
for ;; {
// something to run forever
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.