Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Created September 30, 2014 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jochasinga/d14ad41abd1e2956be10 to your computer and use it in GitHub Desktop.
Save jochasinga/d14ad41abd1e2956be10 to your computer and use it in GitHub Desktop.
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