A question about bracketing conditions...

 

Morning all,

So a quick question about brackets, which is correct?

if(a < b && c < d){

        ...

}

..or do you bracket the individual conditions within the function call, as follows:

if((a < b) && (c < d)){

   ......

}

or does it make no difference at all?

Many thanks and all the best to y'all! 

 
TheHonestPrussian:

Morning all,

So a quick question about brackets, which is correct?

..or do you bracket the individual conditions within the function call, as follows:

or does it make no difference at all?

Many thanks and all the best to y'all! 

The first is correct.

The second is also correct but there is no need for the additional brackets.

The compiler will normally warn you if there is a possible need for additional brackets.

 
Keith Watford #:

The first is correct.

The second is also correct but there is no need for the additional brackets.

The compiler will normally warn you if there is a possible need for additional brackets.

Perfect, thanks Keith. 

 
  1. Perhaps you should read the manual. Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    You should know that Logical AND operation (&&) is lower precedence than less than (<). Thus, the parentheses are redundant.

  2. When mixing ANDs (&&) and ORs (||) always use parentheses.

  3. TheHonestPrussian: So a quick question about brackets,

    Be aware of the different uses of the words brackets/braces.

 
William Roeder #:
  1. Be aware of the different uses of the words brackets/braces.

Ah, so my question should have been, " So a quick question about Parentheses". 


Looking at the documentation for this, I think I'll stick with the US terms. Trust the British to make things complicated! 

Reason: