1.if /else分支判斷
1.if condition {
}
2.if condition {
}else {
}
3.if condition {
}else if condition {
}else {
}
2.switch / case
var i =0
switch i {
case i =0:
pass
//fallthough 可以加fallthough繼續執行后續操作
case i >1:
pass
default: // default 類似于else
pass
}
3.for 陳述句
for 初始化陳述句;條件判斷;變數修改 {
pass
}
1.for i :=0;i<100;i++{
}
2. for i>0 {
pass
}
3.for {
pass
}//死回圈
4.for range
str := "hello world" for i,v := range str { fmt.Printf("index[%d] val[%c] len[%d]\n",i,v.len([]byte(v)))
if i>2{
break
}
}//用于遍歷陣列、slice、map
5.goto和label陳述句
func main() { LABEL1: for i :=0;i<=0;i++{ for j :=0;j<=5;j++{ if j ==4{ continue LABEL1//goto LABEL1 } pass } } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/33548.html
標籤:Go
上一篇:go:函式
