Loops & Decisions (Part1)

 

Hi folks,

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

Loops & Decisions

forLoop

whileloop

ifstatement

if..else statement

switchstatement

I hope you enjoy the lesson and waiting your comments.

Files:
lesson5.pdf  71 kb
 

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?

 
 

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.

codersguru:

for(int i=0;i<15;i++)

{

if((i==10)

break;

Print(i);

}
 

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.

Reason: