If/Else 分支
if 和 else 分支结构在 Go 中非常直接。
代码示例
package main
import "fmt"
func main() {
    if 7%2 == 0 {
        fmt.Println("7是偶数")
    } else {
        fmt.Println("7是基数")
    }
    if 8%4 == 0 {
        fmt.Println("8可被4整除")
    }
    if num := 9; num < 0 {
        fmt.Println(num, "为负数")
    } else if num < 10 {
        fmt.Println(num, "有1个数字")
    } else {
        fmt.Println(num, "有多个数字")
    }
}