当前位置:网站首页>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
边栏推荐
- Brush questions -- sword finger offer
- 一些事情的反思
- Find mapping relationship
- 分布式事务(Seata) 四大模式详解
- Second kill system 3 - list of items and item details
- Jvm-05-object, direct memory, string constant pool
- Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64
- How are integer and floating-point types stored in memory
- Jvm-09 byte code introduction
- Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
猜你喜欢
C language brush questions ~leetcode and simple questions of niuke.com
[cloud native training camp] module VIII kubernetes life cycle management and service discovery
《微服务设计》读书笔记(下)
如何使用 @NotNull等注解校验 并全局异常处理
Microservices - load balancing ribbon
Digital image processing -- popular understanding of corrosion and expansion
Characteristics of MySQL InnoDB storage engine -- Analysis of row lock
百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
CString getbuffer and releasebuffer instructions
秒殺系統3-商品列錶和商品詳情
随机推荐
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
Popular understanding of decision tree ID3
利用MySQL中的乐观锁和悲观锁实现分布式锁
Under VC, Unicode and ANSI are converted to each other, cstringw and std:: string are converted to each other
C language brush questions ~leetcode and simple questions of niuke.com
Jvm-02-class loading subsystem
Popular understanding of ovo and ovr
Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
Kubernetes - yaml file interpretation
Digital image processing -- popular Canny edge detection
深度学习之三维重建
CString的GetBuffer和ReleaseBuffer使用说明
nifi从入门到实战(保姆级教程)——flow
整形和浮点型是如何在内存中的存储
[cloud native training camp] module VIII kubernetes life cycle management and service discovery
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
视觉上位系统设计开发(halcon-winform)
QT common sentence notes
App移动端测试【3】ADB命令
Secsha system 1- login function