Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Lessons
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 10-24-2005, 12:55 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Wink Lesson 5 - Loops & Decisions (Part1)

Hi folks,

Today we will study -what I consider it- the most important MQL4 lesson.

Loops & Decisions

for Loop
while loop
if statement
if..else statement
switch statement


I hope you enjoy the lesson and waiting your comments.
Attached Images
File Type: pdf Lesson5.pdf (70.7 KB, 3579 views)
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm

Last edited by forexts : 11-07-2005 at 08:46 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-01-2005, 06:19 AM
newdigital newdigital is offline
Administrator
 
Join Date: Sep 2005
Posts: 15,422
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Just few questions.

for (int i=0; i>15; i++)
{
if (i==10)
break;
Print (i);
}


As I understand it starts at i=0 and will continue untill the i>15 is true but suddenly it will be stoped because i==10 should be break. Thus we will have the values from 0 to 10 only. Right?

1. It was example for Multistatement in Loops and we used braces (see example). What are the rules to use braces? ({)

2. As I understand i==10 in the example above is the test expression and we must use relation operators instead of simple assignment operators (=). So i==10 is right (because == is relation operator). I am right?

3. What is Print? Do we need to use/write Print in capital letter? Is it printing?
Will we use this "Print" when we will write EA or indicator?

4. Why everything is located like this? I changed the font size but in the example everything is located in some strage way, not the same as you described us in Format lesson that we may use any space etc. A lot of indentions and different indentions: { is located under f letter, i on the next line is using indention, break is under f, P in Print is under i (if) and so on. Do we need to do it? And what are the rules for that indentions?

Last edited by newdigital : 11-01-2005 at 08:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-01-2005, 07:35 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow

Quote:
Originally Posted by newdigital
Just few questions.

for (int i=0; i>15; i++)
{
if (i==10)
break;
Print (i);
}


As I understand it starts at i=0 and will continue untill the i>15 is true but suddenly it will be stoped because i==10 should be break. Thus we will have the values from 0 to 10 only. Right?
You typed the example in wrong way, it must be like that:

for(int i=0;i<15;i++)
{
if((i==10)
break;
Print(i);
}

And it means the loop work every time the Test Expression i < 15 is true.
So, it starts at i=0 and will continue until the i<15 is false
In your example the loop will not work even for one time, because i will never be > 15.

This was an example of Break statement which will terminate the loop when i==10.


Quote:
Originally Posted by newdigital
1. It was example for Multistatement in Loops and we used braces (see example). What are the rules to use braces? ({)
There are no rules of using braces, but you there are some tips:

1- Every opened brace ({) has to be matched with a close brace (}), or you will get an error.
2- There's no semi-colon after the braces.
3- You can use braces too in a single line statement to make your work tidy and readable.



Quote:
Originally Posted by newdigital
2. As I understand i==10 in the example above is the test expression and we must use relation operators instead of simple assignment operators (=). So i==10 is right (because == is relation operator). I am right?
Yes, you are Right, you can't use assignment operator in this case.
Just keep in your mind that == means the question Is Equal.

Quote:
Originally Posted by newdigital
3. What is Print? Do we need to use/write Print in capital letter? Is it printing?
Will we use this "Print" when we will write EA or indicator?
Print is MQL4 built-in function, Its job is printing anything you put inside its parentheses to the experts log (you will find it as a tab below the MetaTrader chart beside the Mailbox tab and before Journal tab).

And it must start with a capital latter, because as you said in the MQL4 Data types lesson the functions names [identifiers in general] are case sensitive, so you have to type it Print.

Quote:
Originally Posted by newdigital
4. Why everything is located like this? I changed the font size but in the example everything is located in some strage way, not the same as you described us in Format lesson that we may use any space etc. A lot of indentions and different indentions: { is located under f letter, i on the next line is using indention, break is under f, P in Print is under i (if) and so on. Do we need to do it? And what are the rules for that indentions?
You can use any amount of spaces or tabs you want.
But, to make your code tidy, readable and it’s a recommended way to avoid bugs in your code. You have to use indentation like the above example.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-27-2006, 09:57 PM
67-17454 67-17454 is offline
Senior Member
 
Join Date: Apr 2006
Location: Oregon
Posts: 112
67-17454 is on a distinguished road
I appreciate your taking the time to provide these tutorials. I haven't programmed in C since the 80's, so this is helping knock off some of the rust.

Not to be trite, but in your next rev of the tutorial, you might want to correct the statement below (it's in your reply above as well as on page 5 of the tutorial) in that the brackets/parenthesis for the 'if((i==10)...' are unbalanced.

Thanks again,

MarkC.

Quote:
Originally Posted by codersguru
for(int i=0;i<15;i++)
{
if((i==10)
break;
Print(i);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/lessons/169-loops-decisions-part1.html
Posted By For Type Date
Strategie i Systemy Forex This thread Refback 07-09-2008 07:33 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 6 - Loops & Decisions (Part2) codersguru Lessons 1 05-18-2007 02:20 PM
Lesson 10 - Your First Indicator (Part1) codersguru Lessons 1 11-08-2005 11:17 PM


All times are GMT. The time now is 09:19 PM.