There are several ways to do this. Here is one:
if (a) {
if (b) {
// do J
} else {
// do K
}
} else {
if (b) {
// do L
} else {
// do M
}
}
You may prefer something more like a truth table, especially if you have more than two tests to combine:
int switcher = 0;
if (a) switcher|=1;
if (b) switcher|=2;
switch(switcher) {
case 0:
// do J
break;
case 1:
// do K
break;
case 2:
// do L
break;
case 3:
// do M
break;
}
I donβt think there is an automatic βrightβ way - you need to choose what is the most clear for your situation.
source
share