OR运算符在Objective C switch语句中

时间:2012-06-15 02:31:08

标签: iphone ios switch-statement

我想知道是否有可能在ta开关声明案例中有一个(||)“或”或(&&)和“运算符。

这就是我的想法。

switch (orientation) {
            case UIDeviceOrientationPortrait:
            {
                case (UIDeviceOrientationLandscapeLeft || UIDeviceOrientationLandscapeRight):
             }
            break;
//...

如果有人可以帮助我,我会非常感激:)

2 个答案:

答案 0 :(得分:10)

&安培;&安培;是不可能的,但你可以实现类似于||的东西通过多个案例不间断:

switch (orientation)
{
   case UIDeviceOrientationPortrait:
       // ...
       break;

   case UIDeviceOrientationLandscapeLeft:
   case UIDeviceOrientationLandscapeRight:
       // ...
       break;
}

您当然也可以在案例块中使用orientation(即进一步评估)

答案 1 :(得分:4)

隐藏OR switch break的结构隐含了

switch (orientation) { case UIDeviceOrientationPortrait: case (UIDeviceOrientationLandscapeLeft: case UIDeviceOrientationLandscapeRight: { } break; }

AND

{{1}}没有意义,因为一个变量不能同时等于两个不同的整数。

相关问题