foreach

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 13 10:03:50 PDT 2014


On Fri, Jun 13, 2014 at 12:54:44PM -0400, Nick Sabalausky via Digitalmars-d wrote:
> On 6/13/2014 5:15 AM, Jonathan M Davis via Digitalmars-d wrote:
> >
> >I'd honestly rather see for(;;) {} removed than have foreach(; 0..n)
> >{} added.  I don't like special cases like like these.
> >
> 
> Disallowing for(;;) would *be* a special case. Each of the three parts
> can be individually omitted, and that is useful. When I only need to
> omit one of the three (and there are times when I do), it's still a
> cleaner more appropriate syntax than turning it into a while. So
> making all three parts required wouldn't really work. And because of
> that, any disallowing of for(;;) would have to be a special case.

FWIW, I also see `for(;;)` as far better than `while(true)`. I like to
read `(;;)` as "ever", so it literally reads "forever { ... }". :-) (In
fact, in C/C++, you *could* #define ever (;;), then you can actually
write "for ever". (Un)fortunately, in D this is not possible.)

I don't like arbitrary constants like the `true` in while(true) -- it
kinda goes against the grain, that "while" implies there is a stopping
point, but sticking true in there contradicts this notion and is
therefore dissonant with the concept of "while". `for(;;)`, OTOH, lines
up very nicely with "forever". :)


T

-- 
People tell me that I'm skeptical, but I don't believe it.


More information about the Digitalmars-d mailing list