-4

我试图检查是否case1和或case2

并想出了以下代码

if(case1 && || case2)..

但这似乎不起作用,甚至可以像这样使用两个运算符吗?如果没有,是否有任何解决方法?

4

4 回答 4

2

No. Either both case1 AND case2 must be true OR one of them.

if (case1 || case2) {....}
于 2013-11-02T10:00:19.550 回答
1

|| is "and/or" already. You'd need to work to get "exclusive or" (a.k.a. XOR).

于 2013-11-02T10:00:44.330 回答
1

AND/OR is the same as OR. You want case1 || case2:

case1    case2   case1 and case2   case1 or case2    case1 and/or case2
  0        0            0                0                 0
  0        1            0                1                 1
  1        0            0                1                 1
  1        1            1                1                 1

As you can see, this is simply an OR.

True OR true is true, that's just how OR works. See http://en.wikipedia.org/wiki/Logical_disjunction.

There's no such thing as an "AND/OR". It sounds like perhaps you were confusing OR with exclusive-OR.

于 2013-11-02T10:02:08.613 回答
0

it wont work and you dont need this either.

There are three conditions:

  1. both condition true
  2. any one of them is true
  3. neither of them is true

For condition 1 && operator

For condition 2 || operator

for condition 3 ~ of 2 condition. As all are mutual excusive you don't need what you have said.

于 2013-11-02T10:00:20.250 回答