forked from steger/pr3-sose2026
32 lines
654 B
Go
32 lines
654 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
|
|
// The if statement is straightforward.
|
|
if 7%2 == 0 {
|
|
fmt.Println("7 is even")
|
|
} else {
|
|
fmt.Println("7 is odd")
|
|
}
|
|
|
|
// You can have an if statement without an else, and the else is optional.
|
|
if 8%4 == 0 {
|
|
fmt.Println("8 is divisible by 4")
|
|
}
|
|
|
|
if 8%2 == 0 || 7%2 == 0 {
|
|
fmt.Println("either 8 or 7 are even")
|
|
}
|
|
|
|
// A statement can precede conditionals; any variables declared in this statement are available in all branches.
|
|
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")
|
|
}
|
|
}
|