Signed-unsigned comparisons in Phobos
Marco Leise
Marco.Leise at gmx.de
Fri Aug 12 06:33:51 PDT 2011
Am 12.08.2011, 15:08 Uhr, schrieb bearophile <bearophileHUGS at lycos.com>:
> Marco Leise:
>
>> Just remember that reverse loops are written like this:
>>
>> for (size_t i = x.length; i-- > 0; ) {...}
>
> Thankfully in D there is foreach_reverse :-)
>
> import std.stdio;
>
> void main() {
> auto array = [10, 20, 30];
>
> for (size_t i = array.length; i-- > 0; )
> writeln(i, " ", array[i]);
>
> foreach_reverse (i, item; array)
> writeln(i, " ", item);
> }
>
> Bye,
> bearophile
Sure, but we were talking about for, not foreach. Maybe these cases in
Phobos cannot use foreach, because they modify 'i' or they don't require
'item'.
More information about the Digitalmars-d
mailing list