Re: while (1) vs. for ( ;; )
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 31 Aug 2005 05:23:11 GMT
"Baxter" <lbax02.spamguard@xxxxxxxxxxx> writes:
[...]
> Why not code it like you would read it in English:
>
> bool done = false;
> while (!done) { // while not done do
> ...
>
> bool mainloop = true;
> while (mainloop) { // while mainloop do
> ...
Because clear English is not necessarily clear C.
You've declared "done" and "mainloop" as variables, which means their
values could change. With "while (1)" (or "for (;;)") I can see at a
glance that the loop is an infinite one; with your suggestion, I can
never be sure unless I analyze the program and verify that "done" will
always be false (and then I'll wonder why the heck you used a
variable).
The clear meaning of "while (!done)" is that the variable "done"
represents a condition that will become true when the loop is meant to
terminate.
I assume that anyone reading my code either is familiar with C, or
just won't be able to understand the code.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- while (1) vs. for ( ;; )
- From: Michael B Allen
- Re: while (1) vs. for ( ;; )
- From: Tim Rentsch
- Re: while (1) vs. for ( ;; )
- From: pete
- Re: while (1) vs. for ( ;; )
- From: Tim Rentsch
- Re: while (1) vs. for ( ;; )
- From: Keith Thompson
- Re: while (1) vs. for ( ;; )
- From: Charlie Gordon
- Re: while (1) vs. for ( ;; )
- From: Baxter
- while (1) vs. for ( ;; )
- Prev by Date: Re: while (1) vs. for ( ;; )
- Next by Date: Re: confused abt file operations
- Previous by thread: Re: while (1) vs. for ( ;; )
- Next by thread: Re: while (1) vs. for ( ;; )
- Index(es):
Relevant Pages
|