Foreach Statement

The foreach statement repeats a group of embedded statements. for each element in an array or an object an collection. The foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the content of the collection to avoid unpredictable side effects.

Example:

class ForEachTest
{
static void main(String [] args)
{
int [] fibarray=new int[]{0,1,2,3,5,8,13);
foreach(int i in fibarray
{
System.console.WriteLine(i);
}
}
}

No comments:

Post a Comment