c++ - Shorten If Statement And Making It Less Redundant -
new here. wondering if it's possible make if statement shorter , less redundant.
if (!a && b) { if (c == d && e > 0) { return; } } else if (a && !b) { if (c != d) { return; } } else if (!a && !b) { return; }
here's i've ended with
if ((!a && b && c == d && e > 0) || (a && !b && c != d) || (!a && !b)) { return; }
all did join nested if
statements &&
operator, , if
-else if
statements ||
operator. i'm stuck, possible make shorter? if share tips or way of approaching kind of scenario, i'd glad hear out.
neither of approaches readable. better create function indicates kinds of checks performing.
if ( !my_very_sensible_special_conditions_are_met(a, b, c, d, e) ) { return; }
after that, whether use first approach or second approach in implementation of function less of issue.
Comments
Post a Comment