Download MetaTrader 5

Compilation error in MT4 not MT5 why?

To add comments, please log in or register
Snelle Moda
633
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?


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

      for(int i = 0; i < 10; i++)
            {
            
            }
     
      }
Alain Verleyen
Moderator
33807
Alain Verleyen  
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
Snelle Moda
633
Snelle Moda  

It works.

Thanks Alain, you are my Hero!

To add comments, please log in or register