Conditional statement true in both parts of if-else-if ladder

后端 未结 4 1803
情话喂你
情话喂你 2020-12-10 09:02

If you have code like this:

if (A > X && B > Y)
{
   Action1();
}
else if(A > X || B > Y)
{
   Action2();
}

With

4条回答
  •  温柔的废话
    2020-12-10 09:27

    If you're talking about C, then only the first block that satisfies the condition is executed - after the control "enters" the conditional block it then "leaves" after all other conditions.

    If you want such behavior, then just use two separate conditions - remove "else" and you have it.

提交回复
热议问题