I donβt see anything wrong with how you do it, but if the result is the same for several conditions, you can simplify it by creating a truth table and simplifying the conditions.
For example, if d should be 0 at any time a false, you can simplify:
if(a) if(b && !c) d = 1; if(!b && !c) d = 2; ... else d = 0;
Or, if there is some mathematical pattern (for example, a , b and c represent three digits of a binary number), you can perform bit arithmetic.
If, however, you have 8 different results (one for each combination of a , b and c ), then your method will be fine.
D Stanley
source share