double[] ar = {1.2, 3.0, 0.8};
int sum = 0;
for (double d : ar) { // d gets successively each value in ar.
sum += d;
}C# :
using System;
class ForEachLoop
{ public static void Main()
{ string[] names = {"Cheryl", "Joe", "Matt", "Robert"};
foreach (string person in names)
{
Console.WriteLine("{0} ", person);
}
}
}
No comments:
Post a Comment