Multiple commands within if statement operator?

 

I want to do something along the lines of

if(conditionA==TRUE)
{
buffer1=1
buffer2=2
buffer3=3
}

Where, if conditionA is true, all three of my commands are executed as a result.

Documentation seems to indicate that the above syntax should work, but I get errors in this format, and no other formats I've tried seem to work either.

Is this possible?

 

I think I figured it out finally (of course after spending a half hour on it I figure it out right after posting).

This syntax seems to work. Does this look correct?

if(conditionA==TRUE)
{
buffer1=1;
buffer2=2;
buffer3=3;
}
 
rrsch #: I think I figured it out finally (of course after spending a half hour on it I figure it out right after posting). This syntax seems to work. Does this look correct?

There is no need to add the "== true". Also, indent your code blocks to make it easier to read.

if( conditionA )
{
   buffer1 = 1;
   buffer2 = 2;
   buffer3 = 3;
};

And if you want to do the equivalent of "!= true" or "== false", just use "!" instead:

if( !conditionA )
{
   // ...
};

or act on both conditions:

if( conditionA )
{
   // ...
}
else
{
   // ...
};
 

Thanks so much.

Question: My code is currently working without the last semicolon (the one after the curly brackets).

Do I need to include that semicolon even if my code is working without it?

 
rrsch #:

Thanks so much.

Question: My code is currently working without the last semicolon (the one after the curly brackets).

Do I need to include that semicolon even if my code is working without it?

No, it's fine. Semi-colons aren't required after curly brackets unless it's at the end of a struct / class definition or an explicitly defined array.

struct SData {};

class CData {};

int data[] = {};
 
rrsch #: Thanks so much. Question: My code is currently working without the last semicolon (the one after the curly brackets). Do I need to include that semicolon even if my code is working without it?

No, it's not necessary in this case. It is just a good practice of mine to always be consistent with my code, given that it is necessary in some cases.