[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

E.5 Brace Placement (if-for-while-do)

The if keyword should be followed by one space, then the opening paren and conditional expression. We also use Stroustrup-style else blocks, rather than the K&R ’cuddled’ else:

if (x) {
...
}
else {
...
}

while (1) {
...
}

for (i = 1; i < 10; i++) {
...
}

do {
...
} while (x);

Single-statement if blocks should be isolated to a single line:

if (x) stmt();

not:

if(x)
    stmt();

Notice that there is a space between if and (x), but not between stmt and (). This should be followed throughout the code.

If an if block has an else if or else, all parts of the construct must be bracketed, even if one or more of them contain only one statement:

if (x) {
    foo();
}
else if (y) {
    bar();
}
else {
    bas();
}

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by root on October 14, 2020 using texi2html 1.82.