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

Ketmar Dark <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #17 from Ketmar Dark <[email protected]> ---
(In reply to entheh from comment #16)
i believe that modifying `i` should be allowed here. but without 'ref' `i` is a
copy of internal counter, so your sample correctly iterates 10 times, updating
`i` to correct value on each iteration. but this works (and it's correct too):

  foreach (ref i; 0..10) {
    ++i; // skip one
    writeln(i);
  }

this outputs 1, 3, 5, 7, 9.

> If 'i' became a new variable for each iteration, then the modify-assign
> would not have the effect intended.
it works this way now. ;-)

--

Reply via email to