Friday, 23 August 2013

Common If Structure

Common If Structure

More and more I find myself writing a structure of If statements that
looks like this:
if(something) {
if(somethingElse) {
// If both evaluate to true.
doSomething();
}
else {
// If the first if is true but the second is not.
doSomethingElse();
}
}
else {
// If the first evaluates the false.
doSomethingElse();
}
Now, to me, this looks horrific. Does anyone have a cleaner way of
representing this logic?

No comments:

Post a Comment