Go

go:流程控制


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
        }
      }
}    

 


作者:kakawith,发布于:2020/03/26
原文:https://www.cnblogs.com/kakawith/p/12573377.html