go:流程控制
程序员文章站
2022-04-23 21:04:57
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 ......
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 } } }
上一篇: Numpy安装