当前位置:网站首页>Go language self-study series | golang switch statement
Go language self-study series | golang switch statement
2022-07-03 15:40:00 【51CTO】
Video source :B standing 《golang Introduction to project practice [2021 newest Go Language course , There is no nonsense , Dry only ! Ongoing update ...]》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Attach summary sticker : Go Language self-study series | Summary _COCOgsta The blog of -CSDN Blog
go In language switch sentence , It is very easy to judge the situation of multiple values .
go In language switch Sentence syntax
go In language switch Statement instance
Judge the grade
Running results
Multiple condition matching
go Language switch sentence , Multiple conditions can be matched at the same time , Separated by commas , If one of them matches successfully .
Running results
case It can be a conditional expression
package main
import (
"fmt"
)
func f() {
score := 90
switch {
case score >= 90:
fmt.Println(" Enjoy the holidays ")
case score < 90 && score >= 80:
fmt.Println(" Study hard !")
default:
fmt.Println(" Study hard !")
}
}
func main() {
f()
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
Running results
fallthrough The next step that meets the conditions can be executed case
package main
import (
"fmt"
)
func f3() {
a := 100
switch a {
case 100:
fmt.Println("100")
fallthrough
case 200:
fmt.Println("200")
case 300:
fmt.Println("300")
default:
fmt.Println("other")
}
}
func main() {
f3()
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
Running results
go In language switch Notes on sentences
- Support multi condition matching
- Different case Do not use break Separate , By default, only one... Will be executed case.
- If you want to perform multiple case, Need to use fallthrough keyword , Also available break End .
- Branches can also use expressions , for example :a>10
边栏推荐
- Tensorflow realizes verification code recognition (II)
- Go语言自学系列 | golang中的if else语句
- 视觉上位系统设计开发(halcon-winform)-4.通信管理
- Popular understanding of decision tree ID3
- leetcode_ Power of Four
- Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
- Popular understanding of gradient descent
- 软件安装信息、系统服务在注册表中的位置
- 驱动与应用程序通信
- Go语言自学系列 | golang中的if else if语句
猜你喜欢
nifi从入门到实战(保姆级教程)——flow
Download and install common programs using AUR
秒杀系统1-登录功能
How to use annotations such as @notnull to verify and handle global exceptions
Kubernetes advanced training camp pod Foundation
Unityshader - materialcapture material capture effect (Emerald axe)
秒杀系统2-Redis解决分布式Session问题
Jvm-09 byte code introduction
App mobile terminal test [5] file writing and reading
【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
随机推荐
Second kill system 3 - list of items and item details
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
深度学习之三维重建
Digital image processing -- popular Canny edge detection
Creation and destruction of function stack frames
CString在多线程中的问题
Jvm-06-execution engine
Microservice - fuse hystrix
Tensorflow realizes verification code recognition (I)
CString中使用百分号
[daily training] 395 Longest substring with at least k repeated characters
使用AUR下载并安装常用程序
需要知道的字符串函数
Unity功能——Unity离线文档下载及使用
WinDbg analysis dump file
XWiki Installation Tips
Popular understanding of linear regression (I)
Secsha system 1- login function
大csv拆分和合并
[cloud native training camp] module VIII kubernetes life cycle management and service discovery