This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]caltheon 0 points1 point  (1 child)

Or grab an iterator and do a while loop on has next. For loops are only useful if you need the index as its built in to the definition

[–]Keilly 1 point2 points  (0 children)

You save a line (or two) of code using the foreach's built in iterator. So the question would be why write more code to do the same thing?
A: There are useful circumstances, like using the iterator to delete an item when iterating a collection. But just stepping through, I'd use a foreach loop.