Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
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 2:36am
Comments
Patrice T 5-Jun-18 4:59am    
You need to explain what are those 54 conditions, because the code you show is absurd.
megaadam 5-Jun-18 5:17am    
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?
[no name] 5-Jun-18 14:43pm    
Are all the possibilities mutually exclusive?

Are "conditions" duplicated among possibilities?

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.
Another advantage is modifications can made by inserting additional blocks in the nest.

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
megaadam 5-Jun-18 10:19am    
Then you must come up with 54 clever names.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900