On Fri, 12 Aug 2011 20:36:32 +0200, Jacob Carlborg <[email protected]> wrote:

On 2011-08-12 20:26, Simen Kjaeraas wrote:
On Fri, 12 Aug 2011 19:19:09 +0200, Marco Leise <[email protected]> wrote:
This way it is actually fun to cripple the for loop, yay. Still if
people started to argue that it is a bad idea to modify variables in
the condition I'd silently agree. So a look at "foreach_reverse (i;
0..x.length) {...}" might be worth it. I guess after a while I will
get used to it. It even reminds me of the Pascal "for"-syntax a bit,
which is "for i := 0 to 9 do ...". It has no receipt for the reverse
zero-length array loop though as far as I know.

Pascal has downto:

for i := 9 downto 0 do ...

If D had uniform function call syntax and good looking delegate literals we could do this:

0.upto(9 ; i) {
     // do something with i
}

9.downto(0 ; i) {
     // do something with i
}

If D had only UFCS of the two, we could do this:

foreach (i; 0.iota(9)) {
   // stuffs
}

foreach (i; 9.iota(0,-1)) {
   // stuffs
}

But yeah, the delegate syntax would also be very nice. I'm not so sure
this is its killer use, though. :p

--
  Simen

Reply via email to