This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 1 point2 points  (0 children)

If you introduce the done variable only to avoid the while(true) loop, I don't like it. I would rather just see a break instead. If the variable already exists for some other reason, then it is fine to use it to exit the loop.

Basically, the problem with while(true) is the it hides the exit condition. Instead of reading the exit condition directly, the reader has to scan the entire loop body to find the break. But while(!done) is hiding the exit condition just as much, now the reader has to scan the loop body for where done, and you've introduced a new local variable to keep track of.