Created
September 30, 2014 01:24
-
-
Save jochasinga/d14ad41abd1e2956be10 to your computer and use it in GitHub Desktop.
Loops in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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