I was coding here the other day, writing a couple of if statements with integers that are always either 0
or 1
(practically acting as bool
s). I asked myself:
When testing for positive result, which is better; testing for int == 1
or int != 0
?
For example, given an int n
, if I want to test if it's true
, should I use n == 1
or n != 0
?
Is there any difference at all in regards to speed, processing power, etc?
Please ignore the fact that the int may being more/less than 1
/0
, it is irrelevant and does not occur.
Human's brain better process statements that don't contain negations, which makes "int == 1" better way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With