Golang关键字
Golang中,if/else 关键字用于条件判断,如果满足条件就做某事,否则做另一件事:if age >= 18 {
fmt.Println(
"成年人")
}
else {
fmt.Println(
"未成年")
}
多重判断:
if score >= 90 {
fmt.Println(
"优秀")
}
else if score >= 70 {
fmt.Println(
"良好")
}
else if score >= 60 {
fmt.Println(
"一般")
}
else {
fmt.Println(
"差")
}
Golang允许在条件判断语句里声明一个变量,该变量的作用域只在该条件逻辑块内:
if score := 40; score >= 90 {
fmt.Println(
"优秀:", score)
}
else if score >= 70 {
fmt.Println(
"良好")
}
else if score >= 60 {
fmt.Println(
"一般")
}
else {
fmt.Println(
"差:", score)
}
页:
[1]