James Franken :
I'm still kind of a newbie so your wisdom and advice would be appreciated.
I've got a tricky if condition and I'm not sure I'm doing this correctly.
if(!conditionOne && conditionTwo){
//do nothing
} else {
//do something
}
I hate having an empty code block for the if but I'm not sure of a better way to do this. This seems like the least amount of code without making it less simple with something like
if(!(!conditionOne && conditionTwo)){
This just looks odd to me but maybe this is better?
Or
if((!conditionOne && !conditionTwo) || (conditionOne && conditionTwo) || (conditionOne && !conditionTwo){
That seems more complicated to me.
conditionOne conditionTwo Outcome
False True Do nothing
False False Do something
True True Do something
True False Do something
What would be the best way to implement this?
Naman :
By De-Morgan's law, you're looking for
if(conditionOne || !conditionTwo) {
//do something
}
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=341213&siteId=1