An even cooler way (that is more concise than myBool = !myBool
for variable names longer than 4 characters if you want to set the variable):
myBool ^= true;
And by the way, don't use if (something == true)
, it's simpler if you just do if (something)
(the same with comparing with false, use the negation operator).