Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 20
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
...
No, I meant:
{
}
for( int i = 0; i < x; i++ )
{
}
...
Yes, and the design you wrote won't work at all.
Every variable has its own scope. Even inside curly braces, there is a separate scope for the variable declared in that scope - inside the curly braces. So why should I, for example, create loop index variables with different names in different places of a program, if I know that they do not overlap, and it is sufficient, and customary, to use such a variable name as "i"?
I did not argue with you.
...
No, I meant:
{
}
for( int i = 0; i < x; i++ )
{
}
...
what is the point? Please share your experience - what might be the problem in this case, i.e. if your code were like this?
for( i = 0; i < x; i++ )
{
}
for( i = 0; i < x; i++ )
{
}
...
I was not arguing with you.
This is my thread. And where bad sub-optimal advice is given, I am entitled to correct the person. You, with respect to the situation at hand, are giving bad advice.
Your thread, then read it carefully and relate the post to the nickname you are replying to.
In short, you're in the wrong place.
but what is the point? Please share your experience - what could be the problem in this case, i.e. if your code would be like this?
for( i = 0; i < x; i++ )
{
}
for( i = 0; i < x; i++ )
{
}
...
When you initialize a counter outside a loop, its scope extends beyond the loop, which is usually not needed. Thus, you provide a fertile ground for possible errors, for example, if further in the code you will have a variable j, and you accidentally call it i. Or instead of index [1] you write [i], etc.
So, variables must be initialized as close as possible to where they are first used and avoid a large number of global variables. This reduces the list of possible errors.
When you initialize a counter outside a loop, its scope extends beyond the loop, which is usually not necessary. By doing this you provide a fertile ground for possible errors, e.g. if further down the code you have a variable j and you accidentally call it i. Or instead of index [1] you write [i], etc.
So, variables must be initialized as close as possible to where they are first used and try to avoid a large number of global variables. This reduces the list of possible errors.
What does this have to do with(....)?
I'm outraged.
If it says i=0 and i++?
Well, change i in another loop?
It will not work
What's that got to do with it?
I'm out.
You can be anywhere and in anything, that's your right. You asked me to explain - I did.
The only thing to consider here is that after the loop block i already equals x, provided that in the loop i<x
Array[i] after for(...){} will return the array overrun error and that's it