The Psychology of Quality and More |
CHAPTER 8 : Language Usage
8.4 Using 'while'The while statement is a fundamental construct of structured languages. With it, all loops can be controlled without recourse to goto. C, in particular, makes heavy use of it, as other loop controls are thinly disguised variations on while. The proper use of a while loop is where it is required to repeat the loop an indeterminate (possibly zero) number of times. The readability of a while loop can be impaired if the comparison becomes false early in the loop:
while ( IsSafeTemp ) -------------------------------------------------------------------------- This can often be improved by putting the comparison-changing statement at the bottom of the block and/or by using else's where they may not be strictly necessary:
while ( IsSafeTemp )
Note that comments made above about comparisons (see 8.2.5) are equally applicable to while statement comparisons.
|
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 |