Signed-unsigned comparisons in Phobos
Timon Gehr
timon.gehr at gmx.ch
Fri Aug 12 06:44:42 PDT 2011
On 08/12/2011 03:33 PM, Marco Leise wrote:
> 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'.
foreach_reverse(i;0..array.length) writeln(array[i]),i--;
More information about the Digitalmars-d
mailing list