Switch语句出错

时间:2014-09-03 07:44:46

标签: objective-c switch-statement

所以这是出现错误的代码行:

switch (ResultCalculation) {// expected indentifier or '/'

    case = 0
        Result = FirstNumber + SecondNumber;
        break;

    case = 1
        Result = FirstNumber - SecondNumber;
        break;

    case = 2
        Result = FirstNumber * SecondNumber;
        break;

    case = 3
        Result = FirstNumber / SecondNumber;

    default :// default statement not in switch statement 
        break ;// break statement not in loop or switch statement
}

1 个答案:

答案 0 :(得分:3)

你的语法错了 - 它应该是:

switch (ResultCalculation) {

  case 0: // <<< *** note the syntax for the case labels! ***
    Result = FirstNumber + SecondNumber;
    break;

  case 1:
    Result = FirstNumber - SecondNumber;
    break;

  // ...

  default:
    break;
}