当前位置:网站首页>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 .
边栏推荐
- RANSAC提取平面(MATLAB内置函数)
- 【数据可视化】使用 Apache Superset 可视化 ClickHouse 数据
- My collection of scientific research websites
- Space transcriptome experiment | what factors will affect the quality of space transcriptome sequencing during the preparation of clinical tissue samples?
- Technical exchange | why should network security equipment use bypass function
- Part I physical layer
- Why is your LDO output unstable?
- Recompile kubeadm to solve the problem of certificate expiration in one year
- Serval and Rooted Tree(CF1153D)-DP
- Pyqt5 technical part - cause of the problem that setting the top of the window does not take effect. Setwindowflags() does not take effect after setting the parameters. Solution
猜你喜欢

Solution to unlimited restart of desktop and file explorer

PHP strtotime 获取自然月误差问题解决方案

输入值“18-20000hz”错误,设置信息不完整,请选择单位

The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%
![[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions](/img/1f/00f2085186971198928b012a3792ea.jpg)
[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions

My collection of scientific research websites

JVM对象分配策略TLAB

Explanation of each column output by explain statement

unity package manager starting server stuck(Unity啟動卡在starting server,然後報錯)

Role of RESNET residual block
随机推荐
可综合RTL代码设计方法和注意事项
Chinese text classification based on CNN
JVM方法区
How to add text on the border in bar code software
BCC tool tool usage
Black circle display implementation
Two end carry output character
Brain cell membrane equivalent neural network training code
周刊02|不瞒你说,我其实是MIT的学生
File upload vulnerability - simple exploitation 2 (Mozhe college shooting range)
Redis第四话 -- redis高性能原理(多路复用)和高可用分析(备份、主从)
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
New product release: domestic single port Gigabit network card is officially mass produced!
[Unity插件]着色器关键字分析工具ShaderControl
JMeter load test finds the maximum number of concurrent users (including step analysis)
JS monitor scrolling touch bottom load more_ Browser scrolls to the bottom to load more
产品资讯|PoE网卡家族集体亮相,机器视觉完美搭档!
使用 float 创建一个网页页眉、页脚、左边的内容和主要内容。
RANSAC提取圆柱(MATLAB内置函数)
Log in with password and exit with error for three times.