# Question about Logical Operation OR ( ||)

914

Can I do this ?
I want all of this || all of that
`if((Alow()!=0 && Bhigh()!=0 && Bhigh() - Alow() >= minABrange*pips2dbl) || (Ahigh()!=0 && Blow()!=0 && Ahigh() - Blow() >= minABrange*pips2dbl))`

I mean will this compare the entire left side and right side entirely ? Or will is stop after the first expression on the right side of || ???

Thanks

Moderator
2333

It will evaluate the left side first, as enclosed with parentheses. If that evaluates as true, it will not bother with the right side as the logic has already been satisfied.

If the left side evaluates as false, only then will it evaluate the right side.

To take it a step further, if Alow()==0 then it will not bother with the rest of the left side because it must evaluate as false; it will skip straight to the right side.

So you need to be careful if those function calls have secondary actions you need completed, as they may never get called.

At least this is my understanding as per Build 600+ based on the information here:

Shortened conditions check is now used in logical operations, unlike the old MQL4 version where all expressions have been calculated and the check has been performed afterwards. Suppose there is a check of two conditions with the use of logical AND

```  if(condition1 && condition2)
{
// some block of operations
}```

If condition1 expression is false, calculation of condition2 expression is not performed, as false && true result is still equal to false.

If you have doubts, you can always put a few Print() statements in your functions to see if they are being called.

914

honest_knave:

It will evaluate the left side first, as enclosed with parentheses. If that evaluates as true, it will not bother with the right side as the logic has already been satisfied.

If the left side evaluates as false, only then will it evaluate the right side.

To take it a step further, if Alow()==0 then it will not bother with the rest of the left side because it must evaluate as false; it will skip straight to the right side.

So you need to be careful if those function calls have secondary actions you need completed, as they may never get called.

At least this is my understanding as per Build 600+ based on the information here:

Shortened conditions check is now used in logical operations, unlike the old MQL4 version where all expressions have been calculated and the check has been performed afterwards. Suppose there is a check of two conditions with the use of logical AND

If condition1 expression is false, calculation of condition2 expression is not performed, as false && true result is still equal to false.

If you have doubts, you can always put a few Print() statements in your functions to see if they are being called.

I see, thanks

`To take it a step further, if Alow()==0 then it will not bother with the rest of the left side because it must evaluate as false; it will skip straight to the right side. `
I do want false for any part of either that is false for that side
However, how does it return the right side if Ahigh()==0 ?
Does it also skip the &&'s ?  Or will it still compare the entire right side and all it's conditions ?

Here is my whole functions for this particular part of my code
```bool ABrange()
{
if((Alow()!=0 && Bhigh()!=0 && Bhigh() - Alow() >= minABrange*pips2dbl) || (Ahigh()!=0 && Blow()!=0 && Ahigh() - Blow() >= minABrange*pips2dbl))
{
return(true);
}
else return(false);
}```

Thanks
Moderator
2333

```if(condition1 || condition2)
{
// some block of operations
}```

I perhaps created some confusion by going into more depth than was probably needed by your question.

With your code, you'll return true if:

condition 1 is true (which means all 3 'sub' conditions are true):

`Alow()!=0 && Bhigh()!=0 && Bhigh() - Alow() >= minABrange*pips2dbl`

or

condition 2 is true (which means all 3 'sub' conditions are true):

`Ahigh()!=0 && Blow()!=0 && Ahigh() - Blow() >= minABrange*pips2dbl`

or

both condition 1 and condition 2 are true.

If neither condition 1 nor condition 2 are true, the function will return false.