For Loop – MQL4 for Complete Beginners Tutorial Part 7

The “for” loop is very similar to the “while” loop, however the “for” loop is much more commonly used. This trend is evident in other programming languages as well as in MQL4. Most likely, the “for” loop is preferred because it is more convenient. In today’s tutorial I will show you how the two loops compare to each other, and you can then decide for yourself which you prefer. Both are equally valid approaches..

Actually, this happens quite a lot in programming. Often, you can implement the same thing in two (or more) different ways, and only your personal preference will guide you to pick one. This is totally normal. Moreover, this is how people develop their own programming styles, which is natural. So congratulations! Today you are making your first step towards developing your personal unique coding style.

Get the full course here: https://www.forexboat.com/learn-mql4

Code For This Tutorial

Tutorial7.mq4:
//+------------------------------------------------------------------+
//| Tutorial7.mq4 |
//| Copyright 2014, ForexBoat |
//| http://www.forexboat.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, ForexBoat"
#property link "http://www.forexboat.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{

for(int i=0; i<5; i++)
{
Alert("Hello");
}

/*

int counter = 1;
while(counter < 3) //true?
{
Alert(counter);
counter = counter + 1;
}

*/

}

 

What are you waiting for?

START LEARNING FOREX TODAY!

Tags:
share This:
Avatar
Muhammad Awais

Leave a Reply

Your email address will not be published. Required fields are marked *

What are you waiting for?

START LEARNING FOREX TODAY!

as seen on: