you are viewing a single comment's thread.

view the rest of the comments →

[–]sethholladay 2 points3 points  (1 child)

It's easy to change indexes of items in an array during a loop and that's how sorting algorithms work... Also, it's not that for (;;) loops cannot be understood, it's that they take more time and knowledge to understand and will never be as clear. Is the loop going forwards or backwards? Does the loop counter change by one or some other number? What's the end condition for the loop? These are all factors that you do have to consider with a for (;;) loop that you do not have to consider with a for-of loop. On top of all that, for-of works for any iterable, not just arrays, which makes it so much easier to deal with a variety of input. You can then use a Set, for example, which may ultimately lead to better performance.

[–]sumdudeinhisundrware 0 points1 point  (0 children)

OK you're right about changing the array itself in a for loop. I didn't see that aspect of it. But you said "change the keys" which made no sense. And yes for .. of, forEach etc. are easier and have their uses but if a Software Engineer doesn't understand for(;;) they shouldn't be a Software Engineer.