Skip to content

Instantly share code, notes, and snippets.

@giwa
Last active August 29, 2015 14:14
Show Gist options
  • Save giwa/bd27c06c3d6973ce2581 to your computer and use it in GitHub Desktop.
Save giwa/bd27c06c3d6973ce2581 to your computer and use it in GitHub Desktop.
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")
}
}
$ 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