C bites (Null loop-bodies)

driehuis%hlerul5.BITNET at Berkeley driehuis%hlerul5.BITNET at Berkeley
Thu Aug 29 04:22:45 AEST 1985


Gary M. Samuelson <garys at bunker.uucp> writes:
>>     I put null loop-bodies on a separate line like in the following
>> example.
>>
>>         while (eatup() != '\n')
>>             ;
>
>Putting the semi-colon on a separate line does help make it clear
>that the body of the loop is intentionally null, but what I like
>even better is:
>
>        while( eatup() != '\n' )
>            continue;
>
>Comments?
Yes. I am not fond of using continue if it is not necessary
to do so. All loop-modyfying statements require an additional
effort to read - at least, for me.
Neither do I like the suggesion I saw in info-c, that read
something like
>        while (function() != READY) {
>             }
The reason why is quite prosaic: when I edit an existing
file into something else, with cutting, pasting, and deleting,
sometimes (no more than once a week :=)) a line or even a
block of text gets lost, leaving embraced white space.
My first reaction to seeing braces, embracing nothing, is: oops...
been too hastily with the delete-line key.
The convention to use a period on a line by itself is
sufficient to recognise at first sight: "this is a null
statement".



More information about the Comp.lang.c mailing list