Download MetaTrader 5
To add comments, please log in or register
What is the best place to find a programmer? Freelance service!
gjrexach
59
gjrexach 2011.05.21 04:11 

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 

Andrei Moraru
1147
Andrei Moraru 2011.05.21 11:18  
Why not just use the parenthesis to be sure in your logical statements outcomes?
Stephen Njuki
5179
Stephen Njuki 2011.05.21 20:55  
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.
investeo
4095
investeo 2011.05.21 22:37  
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
/
To add comments, please log in or register