compare 6 variables

 

Hello,

 i need to compare 6 variables with each other, to enshure that all 6 have different values at the same time.

 for example my simple(but not the best) way to do this:

int a=1;
int b=2;
int c=3;
int d=4;
int e=2;
int f=5;


if (a!=b || a!=c || a!=d || a!=e || a!=f || c!=b || d!=b || e!=b || f!=b || d!=c || ....... )
{
do something when all variables are different...
}

 do you know better way to compare regarding CPU power ?

thanx

L0rd 

 
L0rd1:

Hello,

 i need to compare 6 variables with each other, to enshure that all 6 have different values at the same time.

 for example my simple(but not the best) way to do this:

 do you know better way to compare regarding CPU power ?

Comparing ints should be fast,  I think your method is probably OK.  It doesn't look elegant but use what works first and worry about elegant later of you really need/want to.
 

You could use an array instead of separate variables and loop through the array to check them, it would be neater code but I don't know that it would use less cpu.

 
  1. if (a!=b || a!=c || a!=d || a!=e || a!=f || c!=b || d!=b || e!=b || f!=b || d!=c || ....... )
    {
        will do something when any variable is different...
    }
  2. "regarding CPU power" Don't optimize without testing first. Is that statement REALLY a bottle neck?
  3. if(a!=b) if(a!=c) if(a!=d) if(a!=e) if(a!=f) // Mq4 doesn't have short circuit test with &&
             if(b!=c) if(b!=d) if(b!=e) if(b!=f) // https://www.mql5.com/en/forum/139109
                      if(c!=d) if(c!=e) if(c!=f)
                               if(d!=e) if(d!=f)
                                        if(e!=f)
    {
       do something when all variables are different...
    }

 

thanks guys for fast replys !

 WHRoeder you have right, "or" was wrong. All vars must be different, so i have to use "and".