[Issue 14984] Make it illegal (or at least a warning) to modify the iteration variable in foreach

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Aug 30 05:50:57 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14984

--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
Currently it's intentional. When you declare a index variable in foreach
statement, it works like an auto variable scoped in the foreach body.

If you need non-mutable index variable, you can write code like:

foreach (const i, v; arr) { ... }
foreach (const i; 0..len) { ... }

--


More information about the Digitalmars-d-bugs mailing list