C# Foreach Loop

The foreach Loop

There is also a foreach loop, which is used exclusively to loop through elements in an array (or other data sets):

Syntax

foreach (type 
variableName
 in 
arrayName
) 
{
  // code block to be executed
}

The following example outputs all elements in the cars array, using a foreach loop: Continue reading C# Foreach Loop

C++ The foreach Loop

The foreach Loop

There is also a “for-each loop” (also known as ranged-based for loop), which is used exclusively to loop through elements in an array (or other data structures):

Syntax

for (type variableName : arrayName) {
  // code block to be executed
}

The following example outputs all elements in an array, using a “for-each loop”: Continue reading C++ The foreach Loop