View Single Post
  #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
Reply With Quote