Last active
August 29, 2015 14:14
-
-
Save giwa/bd27c06c3d6973ce2581 to your computer and use it in GitHub Desktop.
Go by Example: If/Else ref: http://qiita.com/giwa@github/items/7a1b01daf0c7ff773315
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() { | |
//例です。 | |
if 7%2 == 0 { | |
fmt.Println("7 is even") | |
} else { | |
fmt.Println("7 is odd") | |
} | |
// elseがなくとも使う事ができます。 | |
if 8%4 == 0 { | |
fmt.Println("8 is divisible by 4") | |
} | |
// 条件式は先に計算され、ここの条件式の変数はどこの分岐でも使う事ができます。 | |
if num := 9; num < 0 { | |
fmt.Println(num, "is negative") | |
} else if num < 10 { | |
fmt.Println(num, "has 1 digit") | |
} else { | |
fmt.Println(num, "has multiple digits") | |
} | |
} |
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 if-else.go | |
7 is odd | |
8 is divisible by 4 | |
9 has 1 digit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment