Another foreach idea.
Dave
Dave_member at pathlink.com
Thu Jun 8 09:25:54 PDT 2006
Kirk McDonald wrote:
> Dave wrote:
>>
>> I can see the problems already - 0 or 1 based? 0 based to be
>> consistent with how many for loops are written now and with array
>> indexing (even though presumably you'd then use foreach with the array
>> itself)? Or 1 based because then it would be WYSIWYG.
>
> This is very much like Python's behavior. In that language, there isn't
> a "for" loop as such, only a "foreach" loop. To loop a counter from 0 to
> 9, you'd write:
>
> for i in range(10):
> print i
>
Thanks for the info. on Python. Since there's precedent with Python, I
guess '0 based' ranges would settle that.
>
> Though honestly, a regular for loop isn't much of a burden.
>
You're right, it isn't, until you run into some time critical loops that
you'd like to leave to the compiler to optimize. And a loop-invariant
condition and 'range' could allow foreach to better do things like loop
unrolling or use vector instructions, I think. It'd be one more thing
that sets D apart too.
> -Kirk McDonald
More information about the Digitalmars-d
mailing list