Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course > Lessons
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 10-24-2005, 01:55 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 994
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 Files
File Type: pdf Lesson5.pdf (70.7 KB, 5020 views)
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm

Last edited by forexts; 11-07-2005 at 09:46 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 11-01-2005, 07:19 AM
Administrator
 
Join Date: Sep 2005
Posts: 20,079
Blog Entries: 241
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 09:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 11-01-2005, 08:35 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 994
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 04-27-2006, 10:57 PM
Senior Member
 
Join Date: Apr 2006
Location: Oregon
Posts: 116
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 02-21-2009, 05:03 PM
Junior Member
 
Join Date: Feb 2009
Posts: 1
dsplzion is on a distinguished road
A little confused

Hi, thanks for all your work.

After your flowchart in Lesson 5 you said:

int i;
int j;
for(i=0,j=0,i<15,i<;i++;j++)
Print(i);

Was the bold part here a typo or was that supposed to be there? I don't see any explanation of why it would be there and you specifically said you can only have one test expression right after this.
Your next example has the same thing as well.


int i;
for(i=15,i>0,i<,i--)
Print(i);

I'm guessing it's gotta just be a typo.

Please let me know, thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 10 - Your First Indicator (Part1) codersguru Lessons 3 04-21-2009 03:52 AM
Lesson 6 - Loops & Decisions (Part2) codersguru Lessons 2 03-17-2009 07:37 PM


All times are GMT. The time now is 08:27 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.