Difference between revisions of "Code Formatting Conventions"

Jump to navigation Jump to search
Update convention for empty loops as discussed on -devel
(Update fallthrough comment in switch example)
(Update convention for empty loops as discussed on -devel)
Line 67: Line 67:
</source>
</source>


'''Semicolons preceded by a space character, if it ends an empty loop body'''
'''Mandatory ''{}'' for empty ''for''/''while'' loops'''


It should also contain a comment to make it clear that the loop is intentionally empty.
<source lang="cpp">
<source lang="cpp">
while (i < length - 1 && array[++i] != item) ; // Look for index of item with an empty loop
while (i < length - 1 && array[++i] != item);   // bad
</source>
while (i < length - 1 && array[++i] != item) {} // good
The following syntax is also acceptable:
<source lang="cpp">
while (i < length - 1 && array[++i] != item)
; //this loop is intentionally empty
</source>
</source>


12

edits

Navigation menu