Go 语言基础教程:6.条件判断

在这篇教程中,我们将通过一个简单的 Go 语言程序来学习条件判断结构的使用。以下是我们要分析的代码:

Go 复制代码
package main

import "fmt"

func main() {

    if 7%2 == 0 {
        fmt.Println("7 is even")
    } else {
        fmt.Println("7 is odd")
    }

    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")
    }

    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")
    }
}
相关推荐
梦想很大很大3 小时前
拒绝“盲猜式”调优:在 Go Gin 项目中落地 OpenTelemetry 链路追踪
运维·后端·go
子玖7 小时前
微信扫码注册登录-基于网站应用
后端·微信·go
Nyarlathotep011312 小时前
gin02:gin路径中的参数
后端·go
极客老墨12 小时前
Go创造者Rob Pike带你深入理解 Go 字符串:字节、符文与 Unicode 编码
go
程序员爱钓鱼15 小时前
Go操作Excel实战详解:github.com/xuri/excelize/v2
前端·后端·go
程序员爱钓鱼1 天前
Go 操作 Windows COM 自动化实战:深入解析 go-ole
后端·go·排序算法
子玖1 天前
实现微信扫码注册登录-基于参数二维码
后端·微信·go
狼爷1 天前
Go 没有 override?别硬套继承!用接口+嵌入,写更清爽的“覆盖”逻辑
java·go
Nyarlathotep01131 天前
gin01:初探gin的启动
后端·go
怕浪猫2 天前
第21章:微服务与分布式架构中的Go应用
后端·go·编程语言