Last active
August 29, 2015 14:14
-
-
Save giwa/7043ae8ce63d1daf87ec to your computer and use it in GitHub Desktop.
Go by Example: For ref: http://qiita.com/giwa@github/items/7237183f7ee3873e8a96
This file contains 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() { | |
// 基本的な型である。単一条件 | |
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 | |
} | |
} | |
This file contains 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
$ go run for.go | |
1 | |
2 | |
3 | |
7 | |
8 | |
9 | |
loop |
This file contains 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() { | |
l := [5]int{1, 2, 3, 4, 5} | |
for e := range l { | |
fmt.Println(e) | |
} | |
} | |
This file contains 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
▶ 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