I’ve seen some code that looks like this:
if (a) return false;
if (b) return false;
if (c) return false;
return true;
Is there any difference in performance between the above and
if (a || b || c) return false;
else return true;
In general, what would be the preferred case to handle this? Maybe without the else in my second example?
EDIT: It seems a lot of people were mislead by the fact that I return true or false and suggest returning !(a || b || c). This wasn’t what I wanted to ask. Imagine if instead of returning true or false I want to return “Yes” or “No”, or 23423 or 3.
It all comes down to how the compiler compiles the code. For all practical purposes, they are identical. (As long as you make sure to use short-curcuited OR “||”)