That’s true Константин Виолован! It would definitely reduce the number of lines written (make it more concise).
I guess it depends on what C1, C2 & C3 actually do, because the context would dictate which approach is more intuitive and readable. For example, in this context it might make more sense to write…
if (isAnimal) { // example 1 if (isDog) {
if (isMaleDog) { return 'is male dog';
} return 'is female dog' } return 'is animal but not dog';}
return 'not animal';
instead of
if (!isAnimal) { return 'not animal' }; // example 2
if (!isDog) { return 'is animal but not dog' };
if (!isMaleDog) { return 'is male dog' };
because I feel like debugging example 1
would be much easier, as the nested conditions are easier to visualise as categories. (that’s how my brain works anyway, you may think differently).
However if you are just simply aiming for exclusion as you’ve demonstrated in your example, with ‘not C1', 'not C2'
etc then your approach would make more sense to me.