Print inside a loop does not work!

 

Hello, can someone explain to me why this does not work?

void OnTick()

  {

myfunction();

  }

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

void myfunction()
  {

for( int i = 5; i == 0; i--)

           Print("LL" + i);

  }
//+------------------------------------------------------------------+
 

Because i==0 is false from the start and the loop is never executed.

You should use i>=0

 

It works as you wrote it.

For loop documentation

Loop runs while condition is true.

In your case it goes like this:

  • set i = 5
  • if i == 0 
    • print
  • else
    • exit loop
  • decrement i
for loop is running while condition is true, not until condition becomes true.
Documentation on MQL5: Language Basics / Operators / Loop Operator for
Documentation on MQL5: Language Basics / Operators / Loop Operator for
  • www.mql5.com
Loop Operator for - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
It was typo error, Thanks!