On 14/06/2014 11:18, Jacob Carlborg wrote:
On the contrary, using while() here is unnatural because while() expects
a loop condition, but since an infinite loop doesn't have one, you have
to artificially invent a constant value to stick into the loop condition
in order to satisfy the syntax of the while-loop. I find this to be
quite unnatural.
I don't agree. How many other statements allow their parts to be
optional. "while" does not, "if" does not.
I'd like while() to mean while(true). The brackets are still there to
avoid confusing simple parser tools. The advantage besides keystrokes
and noise is to unify while(true) and while(1) styles. The latter is
shorter but slightly harder to understand for a beginner.
I prefer using 'while' to 'for' as an infinite loop because while is a
simpler construct (lower level) than for. for is too high level for this
purpose. I think it's easier for beginners to analyse while(true) than
to imagine what each optional part of 'for' means. for with no arguments
devolves into a while loop.