package main
import "fmt"
func main() {
//if 流程控制
score := 90
if score > 90 {
fmt.Println("A")
} else if score >= 70 {
fmt.Println("B")
} else {
fmt.Println("C")
}
//简化写法if 区别,第二种写法定义的变量只能在流程控制语句内使用,相当于局部变量
if score := 60; score > 90 {
fmt.Println("A")
} else if score >= 70 {
fmt.Println("B")
} else {
fmt.Println("C")
}
//for 循环
for i := 0; i < 3; i++ {
fmt.Println(i)
}
//for 循环简写 省略初始语句
num := 0
for ; num < 3; num++ {
fmt.Println(num)
}
// for 循环简写 省略初始和结束语句
sum := 0
for sum < 3 {
fmt.Println(sum)
sum++
}
// for range 遍历数组 、切片、字符串
for i := range 5 {
fmt.Println(i)
}
//switch
fig := 1
switch fig {
case 1:
fmt.Println("你是1")
case 2:
fmt.Println("你是2")
case 3:
fmt.Println("你是3")
case 4:
fmt.Println("你是4")
default:
fmt.Println("无效输入")
}
}
本文为北溟有鱼QAQ原创文章,转载无需和我联系,但请注明来自北溟有鱼QAQ https://www.amdzz.cn
最新评论