// exgl5.go example if then else package main import("fmt") func main() { fmt.Println("go run exgl5.go running") // the normal comparison == != >= <= < > if 8%4 == 0 { // the { must be here, not on next line fmt.Println("8 is divisible by 4") } var n = 2 if ((n < 3) && (n > 1)) || n != 3 { fmt.Println("n=", n) } if 7%2 == 0 { fmt.Println("7 is even") } else { // both } and { must be here, not on other lines fmt.Println("7 is odd") } // A statement can precede conditionals; any variables declared // in this statement are available in all branches. num if num := 9; num < 0 { fmt.Println(num, "is negative") } else if num < 10 { // both } and { must be on this line fmt.Println(num, "has 1 digit") } else { fmt.Println(num, "has multiple digits") } fmt.Println("exgl5.go finished") }