Kesa...小于 1 分钟

5.3 switch 结构

5.3.1 形式1

switch var1 {
case val1:
    // ...
case val2:
    // ...
default:
    // ...
}

5.3.2 形式2

switch 不提供被判断的值,而在 case 中测试不同条件

switch {
    case condition1:
    // ...
    case condition2:
    // ...
    default:
    // ...
}
switch {
	case i < 0:
    // ...
    case i == 0:
    // ...
    default:
    // ...
}

5.3.3 形式3

switch 包含初始化语句:

switch initialization {
    case val1:
    // ...
	case val2:
    // ...
    default:
    // ...
}
switch a, b := arr[i], arr1[j] {
	case a < b:
    // ...
    case a == b: 
    // ...
    case a > b:
    // ...
}
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.2