Go 语言中的判断

204 阅读1分钟

判断(decision making)结构需要指定判定条件和执行语句。 有下面几种类型

if statement

if ... else statement

if (boolean_expression) { /* statements / } else { / statements */ }

nested if statement

switch (con

switch statement

switch (boolean-expresion or integral type) { case boolean-expression or integral type: statement(s); case boolean-expression or integral type: statement(s); default: statement(s) }

switch x.(type) { case type: statements; case type: statements default: statements; }

select statement

select { case communication clause: statement(s); default: /* Optional */ statement(s); }