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")
    }
}
相关推荐
拉勾科研工作室19 分钟前
区块链工程毕业论文题目【249个】
开发语言·javascript
z落落1 小时前
C#WinForm控件实战:Panel与单选框动态创建
开发语言·c#
ptc学习者1 小时前
python 中描述符@property property 大概的样子
开发语言·python
zmzb01031 小时前
Python课后习题训练记录Day129
开发语言·python
张忠琳1 小时前
【Go 1.26.4】Golang Map 深度解析
开发语言·后端·golang
Vertira1 小时前
如何对QT开发的软件进行打包[已解决]
开发语言·qt
AI人工智能+电脑小能手1 小时前
【大白话说Java面试题 第110题】【并发篇】第10题:CAS 存在哪些问题?
java·开发语言·面试
石一峰6991 小时前
C 语言函数设计模式实战经验
c语言·开发语言·设计模式
sitellla1 小时前
Pydub:用 Python 处理音频,不写废话
开发语言·python·其他·音视频