Questions from Beginners MQL5 MT5 MetaTrader 5 - page 496

 
Alexey Kozitsyn:

It will work the way I wrote above.

The compiler warns the user not to be lazy and to put parentheses to avoid possible non-obvious errors.

That's why I don't cram my memory chip with these priorities - I put parentheses and I'm sure it will work as I intended.
 
Alexey Viktorov:
That's why I don't cram my memory chip with these priorities, I put brackets and I'm sure it will work the way I want it to.
I completely agree with you in this, I do the same. But since you asked the question...
 
pako:
So try it.

So I don't need to - why do I need 365 days?


Alexey Viktorov:

Well essentially, yes, the warning is not an error. But how will the initial variant work if( Low[X]>PriceBuy && High[X]>PriceBuy || Low[X]<PriceBuy && High[X]<PriceBuy )? Or can't you put a couple of brackets?

It won't break, I just didn't think it was necessary - or maybe it will change the compiler's priorities logic and it will be necessary for the code to continue working correctly?


Artyom Trishkin:

What good is the compiler here, because the value can still be negative?

In fact, the compiler yells at the "i" well loved by many people ;)

 
-Aleks-:

So I don't need to - why do I need 365 days?


Hands won't be broken, I just didn't think it was necessary - or maybe the compiler's priority logic will change and it's necessary for the code to continue working correctly?


What good is the compiler here, because the value can still be negative?

In fact, the compiler yells at the "i" beloved by many people as much ;)

IfLow[X] is always belowHigh[X], you just have to write

if (Low[X]>PriceBuy || High[X]<PriceBuy), that would work faster!

 
Boris:

IfLow[X] is always less thanHigh[X], it is sufficient to write

if (Low[X]>PriceBuy || High[X]<PriceBuy), that would work faster!

I agree - it can be shorter, I just don't think about optimization when I write it - I put it off for later... Thanks.
 
-Aleks-:

So I don't need to - why do I need 365 days?


Hands won't be broken, I just didn't think it was necessary - or maybe the compiler's priority logic will change and it's necessary for the code to continue working correctly?


What good is the compiler here, because the value can still be negative?

In fact, the compiler yells at the "i", which is a favourite of many people ;)

If it is less than zero, there will be no loop. Are you doing everything thoughtlessly?
 
-Aleks-:

So I don't need to - why do I need 365 days?

In fact, the compiler on many people's favourite 'i' screams just as much ;)

Write it right, there will be no yelling.
 
Artyom Trishkin:
If it's less than zero, there's no loop. Are you doing everything mindlessly?

How does my option differ from yours in such a case?

I couldn't do everything thoughtlessly, but sometimes I wish I could...


pako:
Write it correctly, there will be no yelling.

What's the right thing to do? I'm just learning the basics - that's why I'm asking questions here, why should I say "do it right" if I don't know how it should be right? ;)

So how do I avoid error warnings if loops usually initialize variable "i"?

 
-Aleks-:

How does my option differ from yours in such a case?

I couldn't do everything thoughtlessly, but sometimes I wish I could...


What's the right thing to do? I'm just learning the basics - that's why I'm asking questions here, why should I say "do it right" if I don't know how it should be right? ;)

So, how to avoid error warning when loops usually initialize variable "i"?

Read the variable visibility help.
 
-Aleks-:

What's the right thing to do? I'm just learning the basics - that's why I'm asking questions here, why should I say "do it right" if I don't know how it should be done? ;)

So, how to avoid error messages if loops usually initialize variable "i"?

here it is written in whitehttps://docs.mql4.com/ru/basis/operators/for

Оператор цикла for - Документация на MQL4
  • docs.mql4.com
Оператор цикла for - Документация на MQL4
Reason: