Compilation error in MT4 not MT5 why?

 

Hi all.

I have a mqh file with this example.

When I compile this code in MT4, the compiler gives the error: "'i' - variable already defined"

But when I compile this in MT5 everything is oke. Why does the MT4 compiler generate this error and the MT5 compiler not.

The "i" variable is declared inside the loops, so they should only be visible inside the loop not outside.

Does anyone know why?


void Test()
      {
      
      for(int i = 0; i < 10; i++)
            {
            
            }

      for(int i = 0; i < 10; i++)
            {
            
            }
     
      }
 
Snelle Moda:

Hi all.

I have a mqh file with this example.

When I compile this code in MT4, the compiler gives the error: "'i' - variable already defined"

But when I compile this in MT5 everything is oke. Why does the MT4 compiler generate this error and the MT5 compiler not.

The "i" variable is declared inside the loops, so they should only be visible inside the loop not outside.

Does anyone know why?


Add this to your mql4 code

#property strict
 

It works.

Thanks Alain, you are my Hero!