[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 91

 
sergeev:

2.

as we are not sure that in MT4 the && operations are checked in order, with interruption at false

Thanks for the info, I will correct my code.
 
paladin80:
Thanks for the info, I'll fix my code.

To save reading, I usually write it like this:

// --- 2
if (Stochastic1<=20) if (signal<value) if (flag>Big_flag) if(Ask<=price)
{
   RefreshRates();
   OrderSend(...);
}
 
sergeev:

to save reading, I usually write it down like this:


Thanks for the tip, I got a bit dizzy when I thought "how many inverted commas do I have to fill in, don't miss any and put them in the right places". Being able to write that way brought me back to life.
 
paladin80:
The possibility of such an entry brought me back to life.

just remember that if there is only one operator in a loop/condition, you don't have to use inverted commas.

the main thing is not to get caught up in nested type conditions:

if (cond1)
{
  if (cond2) operator1;
  else operator2;
}

записывать вот так нельзя:

if (cond1)
  if (cond2) operator1;
  else operator2;

так как оператор else непонятно к чему относится
к cond1 или cond2.
 

The advice is clear. Are there any contraindications to using || (or) e.g. here:

if (signal<value || flag>Big_flag)
{  RefreshRates();
   OrderSend(...);
}

.

 
sergeev:

Just remember that if there is only one operator in a loop/condition, you don't have to use inverted commas.

The main thing is not to get caught in nested type conditions:

if (cond1)
{
  if (cond2) operator1;
  else operator2;
}

записывать вот так нельзя:

if (cond1)
  if (cond2) operator1;
  else operator2;

так как оператор else непонятно к чему относится
к cond1 или cond2.

Actually, it's kind of straightforward here: else refers to the nearest earlier if, not closed else. Or am I missing something here?

But in any case, when in doubt, it is better to put all sorts of brackets - both curly and round brackets. I try to do this whenever the structure is non-trivial.

 
paladin80:

The advice is clear. Is there any contraindication to using || (or), e.g. here:

No, you can't put || in if "in a row".

except with an intermediate variable.

bool b1=A1 || A2; // here we can use long conditions

if (b1) // and here b1 can be combined with various other conditions
 
Mathemat:

Actually, it's kind of straightforward: else refers to the nearest earlier if, not closed else. Or am I missing something here?

But in any case, when in doubt, it's better to put all sorts of brackets - curly and round brackets. I always try to do this if the structure is non-trivial.


A proger can easily make a mistake, meaning this

if (cond1)  
{  if (cond2) operator1; }
else  operator2;

instead of this

if (cond1)
{
  if (cond2) operator1;
  else  operator2;
}

understand?

 

I understand, of course. But an experienced coder won't make such a mistake because he puts curly brackets right there, even if there's nothing there yet :)

But an inexperienced one, who saves on brackets and strings (as if it were paper), of course, is more prone to make a mistake.

I was just talking about the parsing rule adopted in modern languages, if there are no braces.

 
Mathemat:

I was just talking about the parsing rule adopted in modern languages if there are no curly brackets.

By the way, did you check which else refers to which if in MT4 and MT5 ?

I've found one without brackets, but I didn't look into it further.
Reason: