OT: for (;;) {} vs while (true) {}

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 03:20:24 PST 2016


On Friday, November 25, 2016 12:10:44 Timon Gehr via Digitalmars-d wrote:
> On 25.11.2016 11:33, Claude wrote:
> > ...
> >
> > Between "for(;;)", "while(true)" and "do while(true)", I would use the
> > "while (true) { }" for pure readability and semantic reasons.
> > ...
>
> What semantic reasons?

Probably the complete lack of a condition to test in for(;;). I confess that
I was shocked when I found out that it was legal to have a for loop without
a condition. That seems like doing while() or if(), which makes no sense.
So, I never use for(;;) and wish that it didn't exist, but it does, and some
folks use it. So, I have to live with the possiblity of dealing with it when
dealing with code written by other people. But I won't ever use it.

- Jonathan M Davis



More information about the Digitalmars-d mailing list