Go by Example - If - Else
Go by Example - If - Else
com/if-else
Go by Example: If/Else
Branching with if and else in Go is straight-
forward.
package main
import "fmt"
func main() {
Logical operators like && and || are often useful in if 8%2 == 0 || 7%2 == 0 {
conditions. fmt.Println("either 8 or 7 are even")
}
$ go run if-else.go
7 is odd
8 is divisible by 4
either 8 or 7 are even
9 has 1 digit
1 of 1 11/26/24, 23:27