当前位置:网站首页>Go language conditional statement
Go language conditional statement
2022-06-11 21:04:00 【Just number six Z】
Go Language conditional sentence
Conditional statements
if sentence
if Boolean expression {
}
if Boolean expression {
} else {
}
if Boolean expression 1{
} else if Boolean expression 2{
} else {
}
Other writing :
// You can include an optional statement component , There is also a variant ( This variant can only be used in if Play a role in the domain )
if statement; condition{
}
if condition{
}
for example :
if num := 4;num>0 {
fmt.Printf("num Positive number ")
}
switch sentence
switch Basic usage of statement
switch Statements are used to perform different actions based on different conditions , every last case Branches are all unique , Test from top to bottom , Until it matches .
switch Statement execution process from top to bottom , Until a match is found , There is no need to add... After the match break.
And if the switch There is no expression , It will match true.
Go Inside switch The default is equivalent to each case Last with break, After the match is successful, it will not automatically execute other case, But out of the whole switch, But you can use fallthrough Enforce the following case Code .
switch var1{
case val1:
...
case val2:
...
default:
...
}
You can also test multiple values that may meet the criteria at the same time , Separate them with commas .
matters needing attention :
1.switch Can act on other types ,case The following values must be the same as switch The type of the variable acting is the same .
2.case Is chaotic .
3.case The last value is unique .
43default Is an optional statement .
边栏推荐
- 13 r basic exercises
- Three waves of changes in cloud computing
- gateway先启动其他微服务,在启动网关,网关启动不了,且无异常日志;先启动网关,所有服务能正常启动
- Go语言for循环
- Teach you how to use win7 system to quickly build your own website
- Tensorflow 2. X Getting Started tutorial
- Docker installing MySQL
- Final examination of Dialectics of nature 1
- Redis第四话 -- redis高性能原理(多路复用)和高可用分析(备份、主从)
- One article to show you how to understand the harmonyos application on the shelves
猜你喜欢

The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%

File upload vulnerability - simple exploitation 2 (Mozhe college shooting range)

第一部分 物理层

php pcntl_ Fork create multiple child process resolution

Modify appid of local wechat applet

Pyqt5 technical part - set the default value of qcombobox drop-down box and get the current selection of the drop-down box

Why should I use iwarp, roce V2, nvme of and other protocols for 100g network transmission

One article to show you how to understand the harmonyos application on the shelves

The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company

Three waves of changes in cloud computing
随机推荐
Unity截屏
【数据可视化】使用 Apache Superset 可视化 ClickHouse 数据
使用 float 创建一个网页页眉、页脚、左边的内容和主要内容。
vectorDrawable使用报错
Solution to the problem of PHP strtotime obtaining natural monthly error
The secret of derating - don't challenge Datasheet
JMeter load test finds the maximum number of concurrent users (including step analysis)
电竞网咖用2.5G网卡,体验飞一般的感觉!
[computer exemption] the Internet of things and ubiquitous intelligence research center of Harbin Institute of technology recruits 2023 graduate students (Master, doctoral and direct doctoral) from un
php pcntl_ Fork create multiple child process resolution
[Unity插件]着色器关键字分析工具ShaderControl
Field queryIndexFieldnameService in xxxImpl required a single bean, but 19 were found:
Gestionnaire de paquets d'Unit é Starting Server Stuck
unity package manager starting server stuck(Unity启动卡在starting server,然后报错)
JSON introduction
Final examination of Dialectics of nature 1
Serval and Rooted Tree(CF1153D)-DP
Online excel file parsing and conversion to JSON format
One article to show you how to understand the harmonyos application on the shelves
Weekly 02 | pour être honnête, je suis un étudiant du MIT