Reputation: 4235
In this question I just want to ask for some ideas. I sometimes run into situations where I end up writing such if
statements, however, I feel like there's a better way to write this as func1()
is written in two places, I believe it should be only in one place.
if (cond1) {
func1();
} else {
if (cond2) {
func1();
} else {
func2();
}
}
How would you write this in a better, and of course readable way?
Upvotes: 0
Views: 83
Reputation: 31296
You've not said what language, but it looks C/Java/C# based...
if (cond1 || cond2) {
func1();
} else {
func2();
}
or similar should work?
Upvotes: 3