Keith Thompson said:
I'd say that a loop with an empty body is sufficiently
unusual that there should be *some* explicit way of
indicating it; otherwise it's easily mistaken for a typo.
I just spotted a typo above! You wrote »it;«, surely you
wanted to write »it,«. (Ok, you could have intentionally
written »it;« in theory, that would not be actually wrong
but very unusual [»The semicolon has been gradually
disappearing, not only from newspapers, but from books« -
slate] and should have *some* explicit way of indicating it
added.)
Ok, if you would be a great literature writer, then you
might use such semicolons without further indications, just
as for example the renowned programmer Donald E. Knuth used
semicolons as loop bodies in a program he wrote two months
ago without further indication:
»for (p=buf;*p==' ';p++);
(...)
for (p=buf+1;*p==' ';p++);
for (q=p+1;*q!='\n';q++);
(...)
for (k=0,cyc[cycptr]=w;w.x!=cyc[k].x || w.y!=cyc[k].y;k++);«
http://www-cs-faculty.stanford.edu/~uno/programs/dragon-calc.w
Ok, this is a short program, and he used this »);« four
times therein, but otherwise this is VERY RARE. We normal
mortal programmers should NEVER take code written by very
good programmers as a model for our own code. It would
be much too smart, no one would understand it anymore,
our coworkers would would think we were arrogant, and,
worst of all, our managers would not be able to read it!
But can we be absolutely certain that Donald E. Knuth did
not make a typo above? Why don't you write a letter to him,
explaining that his loop already ends with this semicolon
(possibly, he will be surprised to learn this!), and suggest
that he double-checks whether this was really intended and
then add some explicit indication to it?
For example, suppose you see this:
while (*p++ = *q++);
do_something;
Yes, but here to clue that hints us of the possibility of an
error is the indentation, not the semicolon. It would be the
same problem with braces:
while (*p++ = *q++){}
do_something;
Or,
while (*p++ = *q++){ /* intentionally empty */ }
do_something;