Precedence under MQL5

 

Does anyone know if the Precedence rules for logical operators(combining && and || in "if" statements) have been normalized to standard C rules?.

There is a mention in the MQL4 manual that states that they deviate, and have found this to be so in some of my code. The combination of && and || in a complex "if" statement  can have unpredictable results(ie. It is my observation that MQ4 would evaluate ALL conditions before taking the path. If you have boolean functions which write/update a file, it will perform the I/O operation even though a preceeding condition was not met.)

Any knowledge of this info will be greatly appreciated!

 

Thanks in advance ,

gjrexach 

 
Why not just use the parenthesis to be sure in your logical statements outcomes?
 
gjrexach:

Does anyone know if the Precedence rules for logical operators(combining && and || in "if" statements) have been normalized to standard C rules?.

There is a mention in the MQL4 manual that states that they deviate, and have found this to be so in some of my code. The combination of && and || in a complex "if" statement  can have unpredictable results(ie. It is my observation that MQ4 would evaluate ALL conditions before taking the path. If you have boolean functions which write/update a file, it will perform the I/O operation even though a preceeding condition was not met.)

Any knowledge of this info will be greatly appreciated!

 

Thanks in advance ,

gjrexach 

For efficiency I never use && or || in if statements. I always handle each condition in the if statement separately and set it to return either true or false.
 
gjrexach:

Does anyone know if the Precedence rules for logical operators(combining && and || in "if" statements) have been normalized to standard C rules?.

There is a mention in the MQL4 manual that states that they deviate, and have found this to be so in some of my code. The combination of && and || in a complex "if" statement  can have unpredictable results(ie. It is my observation that MQ4 would evaluate ALL conditions before taking the path. If you have boolean functions which write/update a file, it will perform the I/O operation even though a preceeding condition was not met.)

Any knowledge of this info will be greatly appreciated!

 

Thanks in advance ,

gjrexach 

Can you give a simple example that does not work for you ? Rules for MQL5 are the same as for C++.

 

https://www.mql5.com/en/docs/basis/operations/rules 

Documentation on MQL5: Language Basics / Operations and Expressions / Precedence Rules
  • www.mql5.com
Language Basics / Operations and Expressions / Precedence Rules - Documentation on MQL5
Reason: