On 08/12/2011 03:33 PM, Marco Leise wrote:
Am 12.08.2011, 15:08 Uhr, schrieb bearophile <bearophileh...@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--;




Reply via email to