当前位置:网站首页>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
边栏推荐
- 关于网页中的文本选择以及统计选中文本长度
- 从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
- Jvm-05-object, direct memory, string constant pool
- The difference between mutually exclusive objects and critical areas
- VC下Unicode和ANSI互转,CStringW和std::string互转
- Enable multi-threaded download of chrome and edge browsers
- Download and install common programs using AUR
- Microservice - fuse hystrix
- Unity功能——Unity离线文档下载及使用
- Get the executable path through the process PID (queryfullprocessimagename)
猜你喜欢

Jvm-08-garbage collector

秒杀系统3-商品列表和商品详情

The markdown file obtains the pictures of the network and stores them locally and modifies the URL

Introduction, use and principle of synchronized

Summary of JVM knowledge points

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

Microservice API gateway

Visual upper system design and development (Halcon WinForm) -3 Image control

Summary of concurrent full knowledge points

Digital image processing -- popular understanding of corrosion and expansion
随机推荐
Introduction, use and principle of synchronized
通过进程PID获取可执行文件路径(QueryFullProcessImageName)
VC下Unicode和ANSI互转,CStringW和std::string互转
Qt常用语句备忘
CString getbuffer and releasebuffer instructions
Subclass hides the function with the same name of the parent class
leetcode_ Power of Four
Puppet automatic operation and maintenance troubleshooting cases
C语言刷题~Leetcode与牛客网简单题
The markdown file obtains the pictures of the network and stores them locally and modifies the URL
Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64
视觉上位系统设计开发(halcon-winform)-4.通信管理
nifi从入门到实战(保姆级教程)——flow
Redis single thread problem forced sorting layman literacy
Driver and application communication
CString的GetBuffer和ReleaseBuffer使用说明
Go语言自学系列 | golang中的if else语句
Halcon与Winform学习第二节
Go语言自学系列 | golang中的if else if语句
Matplotlib drawing label cannot display Chinese problems