当前位置:网站首页>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.
运行结果
边栏推荐
- Digital image processing -- popular Canny edge detection
- 秒杀系统2-Redis解决分布式Session问题
- Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
- Using multipleoutputs to output multiple files in MapReduce
- 视觉上位系统设计开发(halcon-winform)
- Reentrantlock usage and source code analysis
- Reading notes of "micro service design" (Part 2)
- 【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
- Jvm-06-execution engine
- Construction of operation and maintenance system
猜你喜欢

Unity功能——Unity离线文档下载及使用

Can‘t connect to MySQL server on ‘localhost‘
![MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)](/img/cd/2e4f5884d034ff704809f476bda288.png)
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)

Tensorflow realizes verification code recognition (I)

Jvm-05-object, direct memory, string constant pool

How are integer and floating-point types stored in memory

Reading notes of "micro service design" (Part 2)

Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock

Redis主从、哨兵、集群模式介绍

Jvm-08-garbage collector
随机推荐
Popular understanding of ovo and ovr
App移动端测试【5】文件的写入、读取
Halcon and WinForm study section 2
高并发下之redis锁优化实战
Idea does not specify an output path for the module
Jvm-09 byte code introduction
Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
详解指针进阶1
Seckill system 2 redis solves the problem of distributed session
Win10 enterprise 2016 long term service activation tutorial
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
Chapter 04_ Logical architecture
百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
Using Tengine to solve the session problem of load balancing
Kubernetes advanced training camp pod Foundation
函数栈帧的创建和销毁
[combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
Unity功能——Unity离线文档下载及使用
Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)
Visual upper system design and development (Halcon WinForm) -4 Communication management