当前位置:网站首页>Go language basic conditional statement if
Go language basic conditional statement if
2022-06-23 08:07:00 【Ink purple feather ink】
if It's a conditional statement .if The syntax of the sentence is
if condition {
/* stay condition by true When the */
} This is a single conditional statement ,condition by true when , Execute the code in the condition
if condition {
/* stay condition by true When the */
} else {
/* stay condition by false When the */
} If condition by true when , Execute above { Code } Code between , If false when , perform else Code inside
if condition 1 {
/* stay condition1 by true When the */
} else if condition 2 {
/* stay condition2 by true When the */
}else {
/* stay condition1 and condition2 All for false When the */
} The order of condition judgment is from top to bottom . If if or else if The result of conditional judgment is true , Then execute the corresponding code block . If no condition is true , be else The code block is executed .
if condition 1 {
/* condition 1 by true When the */
if condition 2 {
/* condition 2 by true When the */
}
}This statement only satisfies the condition 1, Then the condition will be carried out 2 The judgment of the , If the condition 1 Are not satisfied , Will not judge the conditions 2
elseThe statement should be inifBraces for statements}In the same line after that . If not , The compiler will not pass .
package main
import "fmt"
func test1() {
// if Conditions only make judgments
num := 10
if num >= 0 && num < 10 {
fmt.Println("0 <= num<10")
} else if num >= 10 && num < 20 {
fmt.Println("10<= num <20")
} else {
fmt.Println("num be not in 0~20 Between ")
}
}
func test2() {
// if The condition is assigned first , And then make a judgment
if num := 10; num >= 0 && num < 10 {
fmt.Println("0 <= num<10")
} else if num >= 10 && num < 20 {
fmt.Println("10<= num <20")
} else {
fmt.Println("num be not in 0~20 Between ")
}
}
func main() {
test1()
test2()
}
these two items. test The running result of is the same , But these two test Inside num The scope of is different ,test1 Inside num The scope of is the whole test1,test2 Inside num Only in if The conditions take effect
边栏推荐
猜你喜欢

Talk about routing design in service governance

Tensorboard的使用

Interview questions of a company in a certain month of a certain year (1)

深度学习------不同方法实现lenet-5模型

图像分割-改进网络结构

Apache Solr arbitrary file read replication

Start appium

INT 104_ LEC 06

On ThreadLocal and inheritablethreadlocal, source code analysis

openni.utils.OpenNIError: (OniStatus.ONI_STATUS_ERROR, b‘DeviceOpen using default: no devices found‘
随机推荐
Openvino series 19 Openvino and paddleocr for real-time video OCR processing
Markdown学习
ThreadPoolExecutor线程池实现原理与源码解析
socket编程(多进程)
Hackers use new PowerShell backdoors in log4j attacks
Mathematical knowledge: fast power inverse element - fast power
抓包发现tcp会话中老是出现重复的ack和大量的tcp重传——SACK(Selective Acknowledgment, 选择性确认)技术
Captain Abu's soul torture
Acwing第 56 場周賽【完結】
Location of firewalld configuration file
ArcMap batch delete points closer
81 sentences worth repeating
PHP 文件包含 -ctf
Crawler frame
aquatone工具 中的2个bug修复
值得反复回味的81句高人高语
GTEST death test
aquatone工具 中的2個bug修複
Kwai 350014
VTK. Le bouton gauche de la souris JS glisse pour changer le niveau et la largeur de la fenêtre