Operator
for initiates a cycle. For example, you want to print all numbers from 1 to 10. The straightforward way to do that is to just put 10 lines of
Print() functions:
But it is blunt and inefficient. Imagine if you wanted to print all numbers from 1 to 1,000,000? So in programming, you have cycles to repeat actions multiple times. Using a cycle with a
for operator, you can print the numbers from 1 to 10 much easier:
MQL4:
for (int i = 1; i <= 10; i++) Print(i);
When the cycle starts, the variable
i is assigned the value of "1". On each iteration of the cycle, the command
Print(i) is executed. At the end of each iteration, the command
i++ is executed (
i++ is the same as
i = i + 1). When i gets to "11", the cycle is finished - before it gets to
Print("11").
I hope this helps.