I mean plain iteration uses function calls. Iterators are a more advanced concept that needs wrapper objects and function calls.
> as this is often the sign of a bug.
Why? I've just written that yesterday, I had never a problem with that. For example after deleting an element from an array I need to commit this change, by adjusting the size, etc. Why is it so unexpected that I also need to adjust the index? The index needs to be modified anyway.
Where is the notion coming from that this is less preferable than the workarounds, like marking some elements for deletion and then iterating a second time or by making a second container and moving everything that shouldn't be deleted (.filter) ?
But I need to adjust indices for a container when modifying anyways, regardless whether it occurs in a loop. It's not different than doing not doing it in the loop. Also I'm also modifying the loop index anyways, since I want to iterate, not always touch the same object.
> And sometimes it's a simple bug where you never meant to modify the collection.
How do you accidentally modify an array, which would be different from any other variable?
If the iterator abstracts the iteration away, it should also abstract over the modification.
> Like you cause any other simple bug.
Yes, but we don't forbid modifying other things, just because you could modify them by accident, because you want to modify them some of the time. Why does a[i] = ... needs to be prevented, but a = ... is fine?