August 22, 2008

           Summary: Add else clause to for loops - executed unless break
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

Python has a useful optional else clause on for loops. The else clause is executed unless the loop exits with a break.

See here:


for(int i=0; i<10; i++) {
  if (a[i] == b) {
    printf("found at index %d\n", i);
} else {
   printf("not found\n");

It should be pretty trivial to implement, and is a useful feature.


August 24, 2008

------- Comment #1 from  2008-08-24 18:25 -------
I'd prefer it be named "after" then "else" could be used if the loop never executes even once.