... | ... | @@ -54,3 +54,32 @@ while(1) { |
|
|
} /* end forever */
|
|
|
```
|
|
|
|
|
|
## 1.2 When braces are needed ##
|
|
|
|
|
|
All if, while and do statements must either have braces or be on a single line.
|
|
|
|
|
|
### 1.2.1 Always Uses Braces Form ###
|
|
|
|
|
|
All if, while and do statements require braces even if there is only a single statement within the braces. For example:
|
|
|
|
|
|
```c
|
|
|
if (1 == somevalue) {
|
|
|
somevalue = 2;
|
|
|
}
|
|
|
```
|
|
|
|
|
|
**Justification**
|
|
|
|
|
|
It ensures that when someone adds a line of code later there are already braces and they don't forget. It provides a more consistent look. This doesn't affect execution speed. It's easy to do.
|
|
|
|
|
|
### 1.2.2. One Line Form ###
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```c
|
|
|
if (1 == somevalue) somevalue = 2;
|
|
|
```
|
|
|
|
|
|
**Justification**
|
|
|
|
|
|
It provides safety when adding new lines while maintaining a compact readable form. |