|
|
|
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.
|
|
|
|
|
||||