当前位置:网站首页>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
边栏推荐
- [combinatorics] combinatorial identities (recursive combinatorial identities | sum of variable terms | simple combinatorial identities and | sum of variable terms | staggered sums of combinatorial ide
- Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
- Tensorflow realizes verification code recognition (II)
- Halcon与Winform学习第一节
- The difference between RAR and zip files
- VS2017通过IP调试驱动(双机调试)
- How idea starts run dashboard
- Find mapping relationship
- Summary of JVM knowledge points
- CString getbuffer and releasebuffer instructions
猜你喜欢

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

视觉上位系统设计开发(halcon-winform)

整形和浮点型是如何在内存中的存储

Distributed task scheduling XXL job

Shell script import and export data

关于网页中的文本选择以及统计选中文本长度
![[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解](/img/cd/00954b9c592c253d42e6a3b8298999.jpg)
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解

请做好3年内随时失业的准备?

Final review points of human-computer interaction

Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64
随机推荐
The difference between mutually exclusive objects and critical areas
驱动与应用程序通信
Get the executable path through the process PID (queryfullprocessimagename)
Detailed pointer advanced 2
Use percent sign in CString
Secsha system 1- login function
软件安装信息、系统服务在注册表中的位置
Shell script import and export data
如何使用 @NotNull等注解校验 并全局异常处理
WinDbg分析dump文件
视觉上位系统设计开发(halcon-winform)-5.相机
坚持输出需要不断学习
WinDbg analysis dump file
Seckill system 2 redis solves the problem of distributed session
通过进程PID获取可执行文件路径(QueryFullProcessImageName)
深度学习之三维重建
分布式事务(Seata) 四大模式详解
Detailed pointer advanced 1
Popular understanding of ovo and ovr
CString的GetBuffer和ReleaseBuffer使用说明