Skip to content

Commit

Permalink
CODING_STYLE: explicitly allow braceless 'else if'
Browse files Browse the repository at this point in the history
It's already allowed by the example; there are about 1800 instances in the
tree; and disallowing it would lead to

    if (a) {
        ...
    } else {
        if (b) {
            ...
        } else {
            if (c) {
                ...
            } else {
                if (d) {
                    ...
                } else {
                    ...
                }
            }
        }
    }

instead of

    if (a) {
        ...
    } else if (b) {
        ...
    } else if (c) {
        ...
    } else if (d) {
        ...
    } else {
        ...
    }

which is more readable.

Acked-by: Blue Swirl <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
avikivity authored and Anthony Liguori committed Jul 29, 2011
1 parent ecf169b commit 5f070c5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CODING_STYLE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ keyword. Example:
printf("a was something else entirely.\n");
}

Note that 'else if' is considered a single statement; otherwise a long if/
else if/else if/.../else sequence would need an indent for every else
statement.

An exception is the opening brace for a function; for reasons of tradition
and clarity it comes on a line by itself:

Expand Down

0 comments on commit 5f070c5

Please sign in to comment.