b || c>d || e==f || g

Alternative IF and "OR"

In this code ( a,b,c,d,e,f,g,h,i,j) are the variables):

if ( a>b || c>d || e==f || g<h || i!=j )
{
//Some statement; 
}

If one condition is true among five, it will be satisfied if. However, my actual requirement is that if any three or more of these five conditions are true, then it ifmust be fulfilled. There may be more conditions (10 or more) in the actual code. How can I change the code to set the minimum number of true conditions? I am coding in MATLAB.

+4
source share
1 answer

You can summarize your comparisons and check the amount against a certain number. For instance:

if ( (a>b) + (c>d) + (e==f) + (g<h) + (i!=j) >= 3 )
+8
source

All Articles