New MQL4 variable scope

 
OLD MQL4 NEW MQL4 WITH STRICT
Variable scope is from declaration (even in the nested block) to the function endVariable scope is from declaration to the end of the block, in which the variable is declared


Does that mean in strict mode a local variables scope is defined by { } ?

 
SDC:
OLD MQL4 NEW MQL4 WITH STRICT
Variable scope is from declaration (even in the nested block) to the function endVariable scope is from declaration to the end of the block, in which the variable is declared


Does that mean in strict mode a local variables scope is defined by { } ?


Yes, here's script example :

void OnStart()
  {
  int lol = 4;
//---
   for (int pos = 0; pos < lol; pos ++)
      {
      
      }
   for (pos = 0; pos < lol; pos ++)
      {
      
      } 
  }

when compiled, local variable pos (in red on example above) is an undeclared variable, while variable 'lol' is fine.

Variable 'lol' is in OnStart scope, and the first variable 'pos' is within the scope of first 'for' loop. However the second variable 'pos' is in the scope of second 'for' loop and not declared yet.


 

hmmmm ok thanks OWZ I must have completely missed that in the earlier beta release notes.

Reason: