当前位置:网站首页>Go语言自学系列 | golang中的if else if语句
Go语言自学系列 | golang中的if else if语句
2022-07-03 15:34:00 【51CTO】
视频来源:B站《golang入门到项目实战 [2021最新Go语言教程,没有废话,纯干货!持续更新中...]》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
附上汇总贴: Go语言自学系列 | 汇总_COCOgsta的博客-CSDN博客
go语言if语句可以进行多重嵌套使用,进行多重判断。
go语言中的if else if语法
go语言中的if else if语法实例
根据分数判断等级
运行结果
同样也可以写成这样
运行结果
输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母
package main
import "fmt"
func f6() {
// Monday Tuesday Wednesday Thursday Friday Saturday Sunday
var c string
fmt.Println("输入一个字符:")
fmt.Scan(&c)
if c == "S" {
fmt.Println("输入第二个字符:")
fmt.Scan(&c)
if c == "a" {
fmt.Println("Saturday")
} else if c == "u" {
fmt.Println("Sunday")
} else {
fmt.Println("输入错误")
}
} else if c == "F" {
fmt.Println("Friday")
} else if c == "M" {
fmt.Println("Monday")
} else if c == "T" {
fmt.Println("输入第二个字符:")
fmt.Scan(&c)
if c == "u" {
fmt.Println("Tuesday")
} else if c == "h" {
fmt.Println("Thursday")
} else {
fmt.Println("输入错误")
}
} else if c == "W" {
fmt.Println("Wednesday")
} else {
fmt.Println("输入错误")
}
}
func main() {
f6()
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
运行结果
边栏推荐
- 子类隐藏父类的同名函数
- Kubernetes will show you from beginning to end
- Popular understanding of linear regression (II)
- Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64
- do{}while()的妙用
- The state does not change after the assignment of El switch
- Visual upper system design and development (Halcon WinForm) -5 camera
- Visual upper system design and development (Halcon WinForm) -2 Global variable design
- Using Tengine to solve the session problem of load balancing
- Find mapping relationship
猜你喜欢

Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"

Introduction to redis master-slave, sentinel and cluster mode

Construction of operation and maintenance system

Introduction, use and principle of synchronized

Popular understanding of linear regression (I)

百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式

使用AUR下载并安装常用程序

Unity function - unity offline document download and use

WinDbg analysis dump file

Tensorflow realizes verification code recognition (III)
随机推荐
基于SVN分支开发模式流程浅析
Introduction, use and principle of synchronized
CString的GetBuffer和ReleaseBuffer使用说明
Reading notes of "micro service design" (Part 2)
Characteristics of MySQL InnoDB storage engine -- Analysis of row lock
Kubernetes - yaml file interpretation
Kubernetes带你从头到尾捋一遍
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
Kubernetes vous emmène du début à la fin
Popular understanding of linear regression (I)
WinDbg analysis dump file
Digital image processing -- popular Canny edge detection
《微服务设计》读书笔记(上)
QT common sentence notes
CString getbuffer and releasebuffer instructions
[daily training] 395 Longest substring with at least k repeated characters
秒殺系統3-商品列錶和商品詳情
C language brush questions ~leetcode and simple questions of niuke.com
Detailed pointer advanced 2