[Issue 2304] New: Add else clause to for loops - executed unless break exits
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 22 13:12:49 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2304
Summary: Add else clause to for loops - executed unless break
exits
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: d at strigeus.com
Python has a useful optional else clause on for loops. The else clause is
executed unless the loop exits with a break.
See here: http://docs.python.org/ref/for.html
Example:
for(int i=0; i<10; i++) {
if (a[i] == b) {
printf("found at index %d\n", i);
break;
}
} else {
printf("not found\n");
}
It should be pretty trivial to implement, and is a useful feature.
--
More information about the Digitalmars-d-bugs
mailing list