C # uses a short circuit rating , so performance should be the same.
In a language that does not have a short circuit rating, the latter is likely to be more efficient, but, as with all optimization, you should check to see if there is a gain in performance and decide whether to win the code is much more complex and less maintainable.
In addition, it is possible that such an optimization cannot be an optimization. If the conditions are cheap and the additional complexity increases the size of the code, so that now (for example) it no longer fits the cache, it may actually work less efficiently!
In terms of coding style, this should really be related to what you want to do with else . If you want to do one thing, if everything is true, and the other when it is a lie, select the first. If you want to be able to do different things, depending on which conditions are false, use the latter.
This is not a question of style; it is a question of what you want to achieve. Of course, although if you want to do the same if any value is false, you must use the first form, so in each of the else blocks you will not get the same duplicate code. If in doubt, given two ways to implement the same requirement, it is always recommended to choose the simplest, clearest, most convenient option.
Oh, just in case, if you donβt know, if you want to look forward to the C # conditions, you can use & and | instead of && and || . So, if you want all conditions to be met (possibly for side effects), you can do:
if (CND1 & CND2 & CND3 & CND4) {
However, one thing is that it looks a lot like a short-circuited version, so it's worth commenting on it, especially if C or C ++ people are likely to look at the code.
Also, I find the following lazy construct quite useful:
ok = ok && CND;
But the strict equivalent looks too similar:
ok = ok & CND;
Thus, I make sure that code like this is reset to:
ok &= CND;
Which makes the difference in behavior more apparent.