# Parentheses in IF statements.

• 11-30-2005
thetinman
Parentheses in IF statements.
My question regards the following code.
Code:

```        while (--a >= 0)         {                 f++;                 if (f >= g)                         f = 0;                 h1 = 2;                 if (m)                         h2 = 2;         }```
If the IF statement is false, is the following line, "f = 0," skipped? Are the next two lines skipped? or are the next four line skipped?

Could some one rewrite the code with Parentheses so that is more clear?
• 11-30-2005
Enahs
Code:

``` if (something something something) Do everything up to the first semicolon ;  <- Only this line is executed in the if statement //or if (something something something) { do stuff; as; much; as; you; want; } //End of the if statement. If the if statement was true, it does everything upto this point```
..
Code:

```while (--a >= 0) {                     f++;         if (f >= g)         {                 f = 0;         }//End of if         h1 = 2;//This is always ran in while loop, it is not in any if's         if (m)         {         h2 = 2;         }//End of 2nd if. }//End of while-loop```
• 11-30-2005
SlyMaelstrom
When you don't use brackets around an if statement only the next statement is considered to be in it. There for if your if statement
Code:

`if (f >= g)`
was false, then f would not be set equal to zero, but everything after that would still happen, like h1 would be set to 2.
• 11-30-2005
7stud
The indenting gives a clue about what belongs to the if statement and what doesn't:
Code:

```while (--a >= 0) {         f++;         if (f >= g)                 f = 0;         h1 = 2;         if (m)                 h2 = 2; }```
Here it is rewritten:
Code:

```while (--a >= 0) {         f++;         if (f >= g)         {                 f = 0;         }         h1 = 2;         if (m)         {                 h2 = 2;         } }```
• 11-30-2005
CornedBee
Terminology: braces are {}, brackets are [] (unless further qualified) and parentheses are ().

• 11-30-2005
SlyMaelstrom
Braces, that's the one I was looking for. ;)

... what a ball-buster. :p

Though, I've heard on many occasions braces called brackets and brackets called square-brackets.

...and how the hell do I post braces and brackets outside of code tags? I keep getting the "Format your code properly" error. There must be something I can uncheck or something.
• 11-30-2005
Ancient Dragon
Quote:

Originally Posted by SlyMaelstrom
...and how the hell do I post braces and brackets outside of code tags? I keep getting the "Format your code properly" error. There must be something I can uncheck or something.

I put a space after the bracket, such as [ size ] You should also scroll down the page and check the box "disable simleys in text".
• 11-30-2005
CornedBee
I usually put an empty set of code tags in my post.

[code][/code]
• 11-30-2005
SlyMaelstrom
Ah that's a good idea. Thanks.
• 11-30-2005
ElastoManiac
Is there a way to implement syntax coloring within
Code:

`dfsfdsdfsdf`
, that would be great...
• 11-30-2005
CornedBee
There are some tools that will generate BBcode markup for syntax highlighting code. You put the code there, transform it, and copy the result into the post.

There's also the build-in PHP syntax coloring, which you can access with the php tag, but it only really works for PHP, and doesn't highlight many of C++'s keywords.
• 11-30-2005
Enahs
If you use FireFox and grease monkey you can easily make it auto insert the color tags within the code tag for whatever you want.
http://greasemonkey.mozdev.org/