Does the compound operator require brackets ?

 
Curious if these the same ? 

I assume the compound operators need to be in brackets, but I've seen code written this way and wondered why ? 

Please confirm thanks

   if(A_high()) ObjectSet("B6",OBJPROP_BGCOLOR,clrRed);
   else {
         ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack);
         ObjectDelete("Ahigh");
         }

   if(A_high()) ObjectSet("B6",OBJPROP_BGCOLOR,clrRed);
   else ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack);
          ObjectDelete("Ahigh");
         
 
Agent86:
Curious if these the same ? 

I assume the compound operators need to be in brackets, but I've seen code written this way and wondered why ? 

Please confirm thanks

Is the same as:

   if(A_high()) 
{ ObjectSet("B6",OBJPROP_BGCOLOR,clrRed); }    else
{         ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack);         ObjectDelete("Ahigh");    }    if(A_high())
{ ObjectSet("B6",OBJPROP_BGCOLOR,clrRed); }    else
{ ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack); }
   ObjectDelete("Ahigh");         
 

You don't need brackets for a single operation, but for compound operations, yes.

So Example1 is equivalent to Example2 below.

I suppose its good practice to bracket all, but I do anything to avoid too many brackets!


// Example 1
if(A_high()) 
   { ObjectSet("B6",OBJPROP_BGCOLOR,clrRed); }
   else 
   {
        ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack);
        ObjectDelete("Ahigh");
   }
// Example 2
   if(A_high()) 
    ObjectSet("B6",OBJPROP_BGCOLOR,clrRed); 
   else {
    ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack); 
    ObjectDelete("Ahigh");
  }
 
andrew4789 #:

You don't need brackets for a single operation, but for compound operations, yes.

So Example1 is equivalent to Example2 below.

I suppose its good practice to bracket all, but I do anything to avoid too many brackets!


thanks

 
Agent86:
Curious if these the same ? 

I assume the compound operators need to be in brackets, but I've seen code written this way and wondered why ? 

Please confirm thanks

I am suggesting you to always use brackets. One day or an other it will save you a lot of time.
 
Alain Verleyen #:
I am suggesting you to always use brackets. One day or an other it will save you a lot of time.

I think so too, Thanks