C#Foreach Loop
The foreach Loop
There is also aforeach loop, which is used exclusively to loop through elements in anarray (or other data sets):
Syntax
foreach (typevariableName inarrayName) { // code block to be executed}The following example outputs all elements in thecars array, using aforeach loop:
Example
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};foreach (string i in cars) { Console.WriteLine(i);}Note: Don't worry if you don't understand the example above. You will learn more about Arrays in theC# Arrays chapter.

