There is usually no way to do this: the iterator that is used to βdriveβ the for-each loop is hidden, so your code does not have access to it.
Of course, you can create a class that looks like a collection, which maintains references to all the iterators it creates, and allows you to reset from the side. However, this qualifies as hacking and should be avoided.
If you need a way to reset your iteration to a specific location, use the usual for loop.
source share