simpler if/else

This commit is contained in:
Mark McGranaghan 2012-09-20 20:01:00 -07:00
parent 9b91f7eff7
commit 7011383887
2 changed files with 16 additions and 15 deletions

16
src/11-if-else.go Normal file

@ -0,0 +1,16 @@
// If/Else
package main
func main() {
if 7 % 2 == 0 { // If/else is straightford. Note that there are no
println("even") // enclosing parenthesis around the condition.
} else { // Also, there is no ternary operator (`?`) in Go.
println("odd")
}
}
/*
$ go run 11-if-else.go
odd
*/

@ -1,15 +0,0 @@
package main
import "fmt"
func main() {
i := 1
for i <= 10 {
if i % 2 == 0 {
fmt.Println("even")
} else {
fmt.Println("odd")
}
i = i + 1
}
}