Question

I have a boolean dupe which determines whether two month/year selections are the same... and assigns the appropriate true/false accordingly.

Sometime thereafter, once a certain action is acted upon, dependent on whether dupe is true or not, dupe is turned off (made false)...

I have the following:

dupe = (dupe)?false:dupe;

Which seems fine and I know that works, but I have this weird feeling that it could be made simpler... am I imagining things, or is there a better way of doing this?

I've been staring at this for the good part of ten minutes, and I would rather have an answer than go insane... so can someone please set me straight?

Thanks.

Was it helpful?

Solution

You want this:

dupe = !dupe || false;

However, note that if

dependent on whether dupe is true or not, dupe is turned off

You are setting dupe to false if it's true, and false if it's false, that means it's always going to be false.

So you might as well do this:

dupe = false;

OTHER TIPS

if(dupe){
   dupe =false;
}else{
   dupe=dupe
}

so basically

you are setting dupe=false; whether it is false or true

so you should place dupe= false;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top