Question About the "For Loop"

unaizams

Newbie
Messages
6
Likes
0
Hi,

Question About the "For Loop".

When does one use "for (i=0;i<limit;i++)" and not "for (i=limit;i>0;i--)" or vica versa? In other words, when one has to count from 1 to 10 or the opposite?

Regards.
 
it doesnt matter whether you are counting from 1 to 10 or 10 to 1 as you will still be iterating through the loop 10 times..

for(i = 0 - initialises 'i' and sets value to 0
i<limit - while i is less than limit, carry on the loop
i++ - add 1 to i after each iteration

so.....

for (i = 0; i < 10 ; i++)
console.write(i)

and

for(i = 10 ; i > 0 ; i--)
console.write(i)

would equate to 0,1,2,3,4,5,6,7,8,9 0r 10,9,8,7,6,5,4,3,2,1

but would still iterate 10 times - does this answer your question, or have i misunderstood?
 
it doesnt matter whether you are counting from 1 to 10 or 10 to 1 as you will still be iterating through the loop 10 times..

for(i = 0 - initialises 'i' and sets value to 0
i<limit - while i is less than limit, carry on the loop
i++ - add 1 to i after each iteration

so.....

for (i = 0; i < 10 ; i++)
console.write(i)

and

for(i = 10 ; i > 0 ; i--)
console.write(i)

would equate to 0,1,2,3,4,5,6,7,8,9 0r 10,9,8,7,6,5,4,3,2,1

but would still iterate 10 times - does this answer your question, or have i misunderstood?

Thank you for taking the time to answer.

I am talking about when (in MLQ4) it is suitable, allowed or mandatory to use the incremental counter (i++) and therefore count up and when it is suitable, allowed or mandatory to use the decremental counter (i--) and therefore count down.

For example when:


  • Counting open trades
  • Modifying open trades
  • Closing open trades
  • Deleting pending trades


It appears to me that they are not exchangable in every situation so what is the rule for selecting the right ascending or decending counter?

Best regards,
 
Top