On 08/12/2011 03:08 PM, bearophile wrote:
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

But some people seem to strongly dislike it though. It is a bit unfortunate that you don't currently get the same functionality by using retro.

Reply via email to