在Go语言中,可以使用if语句进行多条件组合判断。以下是一个示例:

package main

import "fmt"

func main() {
    age := 25
    name := "John"

    if age > 18 && name == "John" {
        fmt.Println("成年人且名字是John")
    } else if age > 18 {
        fmt.Println("成年人但名字不是John")
    } else {
        fmt.Println("未成年人")
    }
}

在上面的示例中,使用了&&运算符进行多条件的组合判断。如果年龄大于18且名字是"John",则输出"成年人且名字是John";如果年龄大于18但名字不是"John",则输出"成年人但名字不是John";否则输出"未成年人"。

golang if 多条件组合判断 ok

原文地址: https://www.cveoy.top/t/topic/hLrG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录