These previous array, List, and Dictionary examples showed how to get data into them, and how they store data. It's now time to learn how to loop through the data to retrieve the needed data.
Here are some common ways to perform loops:
foreach loop
for loop
while loop
Using the foreach loop
When working with Collections such as an array, a list or dictionary, the preferred way to cycle through the elements and retrieve data is to use the foreach loop.