Limitations of "For/While Loop"?

 

Hi Everyone,

I have encountered a problem which just makes no sense to me.  Basically I need to search through a long list of hundreds if not thousands of lines in an array.  So I'm using a "While Loop".  This is just an example:

int k = 0;
while(k<300)
{
Print(k);
k++;
}

 

Now, the numbers that start printing don't start at "0", they seem to start arbitrarily somewhere around 200, and this number that is first to print is not the same each time!  The only time the printing starts at "0" is if the while condition is less than 100.  I've tried it with a For loop in the same sort of goal, same problem.  Any idea if MQL4 limits the number of iterations in a loop to about 100?  If so, how do I get around this, as it seems a really daft limitation?

Kind regards

Charles 

 
freemanc:

Hi Everyone,

I have encountered a problem which just makes no sense to me.  Basically I need to search through a long list of hundreds if not thousands of lines in an array.  So I'm using a "While Loop".  This is just an example:

int k = 0;
while(k<300)
{
Print(k);
k++;
}

 

Now, the numbers that start printing don't start at "0", they seem to start arbitrarily somewhere around 200, and this number that is first to print is not the same each time!  The only time the printing starts at "0" is if the while condition is less than 100.  I've tried it with a For loop in the same sort of goal, same problem.  Any idea if MQL4 limits the number of iterations in a loop to about 100?  If so, how do I get around this, as it seems a really daft limitation?

Kind regards

Charles 

All the values aren't displayed in the Experts tab, you have the read the log file (right-click Open inside the Experts tab window).
 
  1. When you print many values quickly, the tab misses some of them. Either look at the actual log file or slow down your printing (sleep) or use dbgView
  2. Use SRC when posting code
  3. While loops and For loops are identical, the latter just places the initialization, test, and change in one place - less chance of getting them wrong, forgetting a part, and usually simplifies the code.
    For loop Template
    Equivalent while loop
    for(INIT; TEST; CHANGE) STATEMENT
    
    INIT;
    while(TEST){
       STATEMENT
       CHANGE
    }
    
     
    for(int k = 0; k<300; k++)
    {
       Print(k);
    }
     
    int k = 0;
    while(k<300)
    {
       Print(k);
       k++;
    }
 
Thank you Guys, that worked perfectly! :-)