I have an if - else if - else condition but I want to pass through all if's until the end to check all conditions. Currently it stops if the first if is true. How do I do that?
Loading
I have an if - else if - else condition but I want to pass through all if's until the end to check all conditions. Currently it stops if the first if is true. How do I do that?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Ganesan CPosted Sep 7, 2021, 4:41 PM
Sandhiya PriyaPosted Dec 6, 2025, 4:10 AM
In C#, if ? else if ? else is exclusive.
That means:
If the first
ifis true ? all other conditions are skipped.else ifruns only when previous conditions are false.If you want to check all conditions, do NOT use
else ifUse multiple independent
ifstatements:Now all conditions will be evaluated, even if the first one is true.
Wrong (skips remaining conditions)
Correct (checks all conditions)
When to keep
else ifUse
else ifonly when conditions are mutually exclusive(only ONE should run).
If you want to check all conditions but run different logic:
Example — checking multiple validation errors:
Marius VasilePosted Sep 7, 2021, 4:53 PM
Ganesan CPosted Sep 7, 2021, 4:50 PM
Marius VasilePosted Sep 7, 2021, 4:22 PM