jloga4
1/2/2017 - 11:29 PM

Foreach loop examples. Second example is from Fundamentals of Computer Programming with C# http://www.introprogramming.info/wp-content/uploa

int[] numbers = {2, 3, 5, 7, 11, 13, 17, 19};
foreach (int i in numbers)
{
  Console.Write(" " + i);
}

Console.WriteLine();

string[] towns = {"London", "Paris", "Milan", "New York"};
foreach (string town in towns)
{
  Console.Write(" " + town);
}

// 2 3 5 7 11 13 17 19
// London Paris Milan New York