You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
It is not a critical issue, but I'm a bit concerned about the future mainteinance of my code, and one thing I noticed is different from other languages (such as C) is the following. I think an example will be the easiest way to explain myself:
Invalid MQL4 code:
However, the equivalent C code is valid:
My concern with this is whether this is a bug in the MQL4 compiler or if this is intended. I have searched through the docs and found this page: https://docs.mql4.com/basis/variables/variable_scope where it says: "A variable declared inside a block (part of code enclosed in curly brackets) belongs to the local scope.". So it seems it is intended to be this way.
However, the following code also fails to compile:
As of now, I'm writing my code the following way:
In my real life scenario, I have more variables (not necessarily integers) with the same name in various loops, and I keep the declaration of all of them outside any loop. I feel this makes my code harder to maintain.
My question is, is it safe (by safe I mean, random-unexpected-results-free) to declare variables in for loops statements (or within a for loop block) and then have other variables without declaration in other loops/blocks of code?
I hope my point is easy to understand, because english is not my mother tongue.
Cheers.