This commit is contained in:
Mark McGranaghan 2012-09-23 12:14:54 -04:00
parent b2bae182ee
commit ae112de5ae
3 changed files with 19 additions and 17 deletions

View File

@ -1,17 +0,0 @@
package main
import "fmt"
func main() {
fmt.Print("7 is ")
if 7 % 2 == 0 { // If/else is straight-forward. Note that there are no
fmt.Println("even") // enclosing parentheses around the condition.
} else { // Also, there is no ternary operator (`?`) in Go.
fmt.Println("odd")
}
}
/*
$ go run 11-if-else.go
7 is odd
*/

17
009-if-else/if-else.go Normal file
View File

@ -0,0 +1,17 @@
// ## If/Else
package main
import "fmt"
func main() {
// If/else is straight-forward. Note that there are no
// enclosing parentheses around the condition.
// Also, there is no ternary operator (`?`) in Go.
fmt.Print("7 is ")
if 7%2 == 0 {
fmt.Println("even")
} else {
fmt.Println("odd")
}
}

2
009-if-else/if-else.sh Normal file
View File

@ -0,0 +1,2 @@
$ go run if-else.go
7 is odd