Skip to content

Instantly share code, notes, and snippets.

@giwa
Last active August 29, 2015 14:14
Show Gist options
  • Save giwa/7043ae8ce63d1daf87ec to your computer and use it in GitHub Desktop.
Save giwa/7043ae8ce63d1daf87ec to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
// 基本的な型である。単一条件
i := 1
for i <= 3 {
fmt.Println(i)
i = i + 1
}
//古典的な 初期化式/条件式/最初期化式
for j := 7; j <= 9; j++ {
fmt.Println(j)
}
// 条件がないforはbreakされるかreuturnをループ内でしない限り続く。
for {
fmt.Println("loop")
break
}
}
$ go run for.go
1
2
3
7
8
9
loop
package main
import "fmt"
func main() {
l := [5]int{1, 2, 3, 4, 5}
for e := range l {
fmt.Println(e)
}
}
▶ go run foreach.go
0
1
2
3
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment