陪玩app源码,Go 语言的循环及条件语句
循环
Go 语言只支持 for 循环。
funcTestWhileLoop(t*testing.T){n:=0forn<5{n++fmt.Println(n)}}无限循环
n:=0for{fmt.Println(n)}IF条件语句
funcTestIf(t*testing.T){ifa:=1==1;a{t.Log("1 == 1")}}switch 条件语句
Go 语言的 switch 不需要使用 break 来退出一个 case
funcTestSwitch(t*testing.T){fori:=0;i<5;i++{switchi{case0,2:t.Log("Even")case1,3:t.Log("Odd")default:t.Log("not 0-3")}}}case 中使用表达式:
funcTestSwitchCondition(t*testing.T){fori:=0;i<5;i++{switch{casei%2==0:t.Log("Even")casei%2==1:t.Log("Odd")default:t.Log("unknow")}}}以上就是陪玩app源码,Go 语言的循环及条件语句, 更多内容欢迎关注之后的文章