Consider this code -
if(enable) {
if(enableCar) {
// do something
} else if(enableComputer) {
// do something
} else if(enableTV) {
// do something
} else {
otherChoice();
}
} else {
otherChoice();
}
// More code here so return isn't possible
How should i avoid so much else
statements, i can't remove the if(enable)
because a carEnable
can return true while enable
itself will be false.
I can't use return as i have more code below
So how should i avoid so much else
statements?
Of course it's just an example :)
Thanks