15,789,840 members
1.00/5 (1 vote)
See more:
i need to check all 54 possibilities what is the best way to check it present i am using if else conditions

What I have tried:

```ex:

<code>
//first 3 conditions have a,b,c values
if(a=a && a=a && a=a && a=1)
{
//logic
}
else if(a=a && a=a && a=a && a=0)
{
//logic
}
else if(a=a && a=a && a=b && a=1)
{
//logic
}
</code>```
Posted
Updated 5-Jun-18 3:36am
Patrice T 5-Jun-18 4:59am
You need to explain what are those 54 conditions, because the code you show is absurd.
He can always try posting that at stackoverflow :p
Richard MacCutchan 5-Jun-18 5:30am
It depends on what you are trying to do but there is probably a better way. And what you have shown above is not it (as ppolymorphe already commented).
CPallini 5-Jun-18 6:33am
Do you know your code doesn't make sense?
Gerry Schmitz 5-Jun-18 14:43pm
Are all the possibilities mutually exclusive?

Are "conditions" duplicated among possibilities?

## Solution 1

One possibility, again dependent upon what you're planning is to reorganize it to nested conditionals
C#
```if(a==a1) {
if(b==b2) {
if(c==c3) {
}
else{
}
}
else{
}
}
else {
// Same content as above for the conditional tests
}```
One advantage of the above is you only do each test once.

Realize that a block may contain more than one else if you have more than one value you are testing for, but then you ought to consider using a switch for that particular test.

This solution is essentially generic:
Your goals should be a combination of trying to do each test only once and thus building a path to each result and making it flexible, using if() or switch() as appropriate.

## Solution 2

Set a variable to 1 - 54 based on the conditions and then have a switch statement that executes the logic based on the value of that variable.