MQL logical AND and OR operator semantics

 

If you compile and run the attached source code, you will see the "test() is called" output of Comment(). That proves that unlike C/C++ despite the fact 'condition' is set to false, test() DOES get executed.


This causes a lot of confusion for the C/C++ programmers who are used to a different logical AND semantics whereby test() will NOT get executed unless 'condition' is true. Such unnecessary confusions can create extremely hard to debug cases.


Does anyone know why such unfamiliar semantics are chosen? i.e. What are the benefits?

Files:
 
bbehzadimql:

If you compile and run the attached source code, you will see the "test() is called" output of Comment(). That proves that unlike C/C++ despite the fact 'condition' is set to false, test() DOES get executed.


This causes a lot of confusion for the C/C++ programmers who are used to a different logical AND semantics whereby test() will NOT get executed unless 'condition' is true. Such unnecessary confusions can create extremely hard to debug cases.


Does anyone know why such unfamiliar semantics are chosen? i.e. What are the benefits?

Same unfamiliar semantics for logical OR. See the attachment.

Files:
 

Note that this behavior is explicitly written in the documentation (from -> MQL4 Reference -> Basics -> Operations & Expressions -> Boolean operations):

Logical expressions are calculated completely, i.e., the so-called "short estimate" method does not apply to them.

As to why such unfamiliar semantics was chosen, don't really know. But you can ask Rosh or one of the other MQ forum moderators...

Reason: