Summary: Stride in foreach ranges
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-04-21 14:09:48 PDT ---
In D2 the range syntax of foreach is useful because it helps state the
iteration variable one time only instead of tree, it's cleaner and less
bug-prone than the normal for syntax, and it's useful in many situations
because many for loops are just over a numeric range (so the normal for syntax
can be left for more complex situations).

But beside natural series, for loops over arithmetic ranges too are common.
Currently in D2 this requires a normal for syntax:

for (int i = 0; i < 100; i += 2) {}

My experience with Python tells me that an optional stride can be useful here.
This is a possible syntax (the colon is useful to visually tell apart the third

foreach (i; 0 .. 100 : 2) {}

(To keep things simpler, it can even be acceptable for the stride value to be a
value known at compile-time).

See also bug 4111.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to