Enhanced for loop

[This question is more about java than C++, but thanks to this last one I began to think more deeply]

Is that possible to change the values of array using an enhanced for loop in java, as we can do in C++ using a reference variable to iterate through the array?

1
2
for (int& i : array) 
     ++i;
Last edited on
In short: no

http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html
Similarly it is not usable for loops where you need to replace elements in a list or array as you traverse it


http://stackoverflow.com/a/19828685/3410396
If you want to edit elements, use the original for loop
Topic archived. No new replies allowed.