Testing for multiple if statements [duplicate]

6 days ago 7
ARTICLE AD BOX

I have a bulky set of if statements, and what I want is that if none of them trigger, only then do I want the "else" to work. But each if needs to work independently, and multiple of them need to be able to trigger.

I currently have it set up like this:

bool check = true; if (check1) { DoSomething1(); check = false; } if (check2) { DoSomething2(); check = false; } if (check3) { DoSomething3(); check = false; } if (check4) { DoSomething4(); check = false; } //... several more checks //If all ifs above failed, check will still be true if (check) DoDefault();

Is there a better way to do this?

CocoaMix86's user avatar

3

Read Entire Article