The Psychology of Quality and More |
CHAPTER 6 : Layout
6.10 Empty statementsEmpty statements naturally occur after control statements where the entire operation is contained within the control statement. This is, in effect, a special case of the single statement as described above, and similar rules may be used. Putting the semicolon at the end of the line can be confusing, even though the next line is not indented. The careful reader will be alerted by this, and will want to check that this is what was intended:
for ( i = 0; i < ARRAY_MAX; NewArray[i++] = 0 ); ------------------------------------------------- A clearer alternative is to put the semicolon by itself on the next line, either below the for or indented, where the intent is explicit, saying "Do nothing". For additional confirmation, a comment may be added:
for ( i = 0; i < ARRAY_MAX; NewArray[i++] = 0 )
Another alternative is to use an empty set of braces. This is sticking to the simple 'braces with everything' rule, is not likely to be missed, and eases later line insertion. This is at the cost of additional brace-only lines (although, in practice, these are not likely to happen too often).
for ( i = 0; i < ARRAY_MAX; NewArray[i++] = 0 )
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |