[…] I wanted to write this more modern and elegant. […]
You cannot use
for … in … do for that. The problem is the loop body receives a
copy of the array member’s value. In the loop body, the collection (the array) you specified between
in … do, is
not touched again.
Only by using a
for … to … do loop and writing
myArray[myCountingVariable] you
actually have access to the array and can manipulate it, its contents.
This compiles AND works:
Yeah, OK, handling pointers to pointers. That’ll just circumvent the immutability requirement (as far as the compiler can detect it). What’s the gain, the advantage though? Frankly, it’s nice that it works, but I’d probably opt for the more intuitive/readable solution.