go语言学习笔记3----流程控制

1 条件语句

if a<5{  //注意条件没有小括号

  //

}else{

  //

}

2 选择语句

switch i {

  case 0:

    //

  case 1 :

    //

  default:

    //

}

switch 后面的表达式不是必须的

switch{

  case a>0:

    //

  case a<0:

    //

}

提示:左花括号必须与switch处于同一行

    条件表达式不限制为常量或者整数

    单个case中,可以出现多个结果选项

    匹配成功不需要break跳出,自动跳出

    不要跳出使用fallthrough

3 循环语句

go语言只有for循环,没有while,do while

for i:=0;i<10;i++{

}

Computers are a sadness,I am the cure.
原文地址:https://www.cnblogs.com/anxiong/p/9776596.html