if-else
This commit is contained in:
parent
b2bae182ee
commit
ae112de5ae
@ -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
17
009-if-else/if-else.go
Normal 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
2
009-if-else/if-else.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
$ go run if-else.go
|
||||||
|
7 is odd
|
Loading…
x
Reference in New Issue
Block a user