When you're working with collections of data, whether
Stack, or others, you'll typically want to iterate (or traverse) all items in the list or at least some items, based on a specific criteria. In some cases, you'll want to loop through all items in sequence or some items. Most often, you'll want to traverse the items forwards in sequence, but as we've seen, there are times when reverse traversing is also suitable. You can loop through items using a standard for loop. However, this raises some annoyances that the interfaces of
IEnumerator can help us solve. Let's see what the annoyances are. Consider the
for loop in the following code sample 6-5:
//Create a total variable int Total ...