Download MetaTrader 5

Correct brackets/bracers {} - page 2

To add comments, please log in or register
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  

Try again ..

if(2+1>4){ Print("3"); } Print("4");   // returns 4

if(2+1>4){ Print("3"); Print("4"); }   // returns 3 and 4 OR not ?

Make sure don't change anything in the code.

pontuso5
376
pontuso5  
deysmacro:

Try again ..

Make sure don't change anything in the code.


Your second example in src box.
if(2+1>4)//3 is not bigger then 4

{ Print("3"); Print("4"); }   //No print will be done


if(2+1<4)//3 is less then 4

{ Print("3"); Print("4"); }   //Print will be done


I understand this but what i mean is this, witch is not equal to your first example in your src box.

 if(2+1>4)//3 is not bigger then 4
{ Print("3"); } Print("4");   //returns 4


 if(2+1<4)//3 is less then 4
{ Print("3"); } Print("4");   //returns 3 and 4

And wrapping these, there is no difference is in result!

 {if(2+1>4)//3 is not bigger then 4
{ Print("3"); } Print("4");}   //returns 4

 {if(2+1<4)//3 is less then 4
{ Print("3"); } Print("4");}   //returns 3 and 4

So wrapping in the whole icustom function with brackets, wont do any diffrence, unless its not a part of a complex logic.?

whroeder1
15584
whroeder1  
pontuso:
So wrapping in the whole icustom function with brackets, wont do any diffrence, unless its not a part of a complex logic.

Correct brackets/bracers {}

double p0, p1, p2, p3, p4, p5;
i=0;
while(n<5)
{
   if(p0>0) {p5=p4; p4=p3; p3=p2; p2=p1; p1=p0; }
   p0=iCustom(Symbol(),​­ 0, ­​"mycustomindicator",­​ 0,­​ 0,­​ 3,­​ 0,­​ i);
   if(p0>0) {n+=1; }
   i++;
}
  1. Correct
  2. Be aware of the different uses of the words brackets/braces
    CharacterUS EnglishUK EnglishIndia
    ()ParenthesesBraces, round brackets, curved brackets, oval brackets
    []BracketsSquare Brackets
    {}BracesCurly bracketsflower bracket
    <>Angle brackets (or chevrons)
  3. What happens when you don't have five positive numbers on the chart? Simplify your logic?
    double p[5];
    int n=0;
    for(int i=0; i < Bars && n < 5; ++i){
       p[n] = iCustom(Symbol(),­​ 0,­​ "mycustomindicator",­​ 0,­​ 0,­​ 3,­​ 0,­​ i);
       if(p[n]>0) ++n;
    }
Ian Venner
2584
Ian Venner  

lacement of braces is uber important.

When you use any of the operators. if, while, for etc. The braces define the scope of the operator.

example

if( var1 == var2 )

a=10;    
b=20;
c=30;

// no braces is the same as braces around only the first operation so only a=10; is dependent on the if condition.

if( var1 == var2 )
 {
 a=10;
}
b=20;
c=30;

// b=20; c=30; are not included in the if operations and will be executed regardless in both cases.



if(var1 == var2)
{
 a=10;
 b=20;
}
 c=30;

//this time the braces mean both a=10; and b=20; will be executed when the if condition is true.
//c=30 is still outside the scope of the if operator and will be executed regardless
whroeder1
15584
whroeder1  
SDC:
lacement of braces is uber important.

When you use any of the operators. if, while, for etc. The braces define the scope of the operator.

Except that isn't what OP is asking/doing.
function(){
   code
   code
   {         // Useless brackets
     code
     code
   }         // Useless brackets
   code
}
Ian Venner
2584
Ian Venner  
WHRoeder:
SDC:
lacement of braces is uber important.

When you use any of the operators. if, while, for etc. The braces define the scope of the operator.

Except that isn't what OP is asking/doing.



Well yeah, but still, if he knows what they are supposed to be for he might better understand when they are not required.
12
To add comments, please log in or register