【问题标题】:Compare a number in a switch statement比较 switch 语句中的数字
【发布时间】:2012-11-08 03:31:42
【问题描述】:

我需要比较 switch 语句中的 int,但我不确定我是如何输入错误的。这是我的代码:

switch (y) {
    case int y isgreater(1, 411):
       // case code here...

为了简化我想要的,在 VB 中,代码是:

Case >= 411:
  'Code here for case

【问题讨论】:

    标签: objective-c ios xcode switch-statement


    【解决方案1】:

    Objective-C 等基于 C 的语言不支持这种语法。只需使用if 声明:

    if (y >= 411) {
        // do stuff
    }
    

    switch 语句中,每个case 值必须是离散常量。

    switch (expression) {
        case 5:
            // stuff
            break;
        case 12:
            // stuff
            break:
        default:
            // stuff
            break;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-04
      • 2016-08-09
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 2018-03-23
      相关资源
      最近更新 更多