当前位置:网站首页>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
边栏推荐
- 自定义注解
- Automatic generation of client code from flask server code -- Introduction to flask native stubs Library
- 软件逆向破解入门系列(1)—xdbg32/64的常见配置及功能窗口
- Redis高可用与持久化
- Jvm-08-garbage collector
- 分布式事务(Seata) 四大模式详解
- Kubernetes - yaml file interpretation
- Large CSV split and merge
- Detailed pointer advanced 2
- Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
猜你喜欢

求字符串函数和长度不受限制的字符串函数的详解
![[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller](/img/a4/2156b61fbf50db65fdf59c8f5538f8.png)
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller

关于网页中的文本选择以及统计选中文本长度

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

Jvm-06-execution engine

Download and install common programs using AUR

Redis cache penetration, cache breakdown, cache avalanche solution

Halcon与Winform学习第二节

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

Microservice API gateway zuul
随机推荐
Atlas atlas torque gun USB communication tutorial based on mtcom
Microservice API gateway
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
VS2017通过IP调试驱动(双机调试)
Win10 enterprise 2016 long term service activation tutorial
XWiki Installation Tips
Redis single thread problem forced sorting layman literacy
Popular understanding of decision tree ID3
[daily training] 395 Longest substring with at least k repeated characters
Redis cache penetration, cache breakdown, cache avalanche solution
Visual host system design and development (Halcon WinForm)
Puppet automatic operation and maintenance troubleshooting cases
Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
Large CSV split and merge
大csv拆分和合并
Introduction to redis master-slave, sentinel and cluster mode
Seckill system 3- product list and product details
Visual upper system design and development (Halcon WinForm) -4 Communication management
Markdown file titles are all reduced by one level