simpler if/else
This commit is contained in:
parent
9b91f7eff7
commit
7011383887
16
src/11-if-else.go
Normal file
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
|
||||
*/
|
15
src/11-if.go
15
src/11-if.go
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user