2

我想知道是否有任何方法可以通过不中断的开关多次验证。例如:

 switch(case){
        case case1:
           //do things... many things.

        case case2:
           //do things... many things.

        case case3:
           //do things... many things.
           break;
}

我想要的是代码运行 case1 并且在 case2 之后只有如果 case 2 也被批准。我使用 switch 而不是 case 的原因是因为在这种情况下,一个并不意味着另一个,但可能与它一起存在,反之亦然。可能没有。像这样:

A! Is B? 
   Yes! A and B
   No!  A
B! Is A? 
   Yes! B and A
   No! B
A? B? NOT A and NOT B

我知道我可以使用 if 和连词,但我想知道是否有一种“直接”的简单方法。

4

2 回答 2

1

简单有什么问题if

if (A && B) {
...
} else if (A) {
...
} else if (B) {
...
}
于 2013-10-19T13:10:01.387 回答
0

我想知道是否有任何方法可以通过不中断的开关多次验证

如果没有休息,您将无法正确使用开关

至于您的解决方案,您需要 if 语句而不是 switch

就像这样:-

if (A && B) 
{
 //do many things here
} 
else if (A) 
{
//do many things here
} 
else if (B)
{
//do many things here
}
于 2013-10-19T13:10:14.253 回答