asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Programming Languages Primer > Foreach Loops

ASP.NET Programming Languages Primer


The foreach statement ( For Each...Next in VB ) executes embedded statements for each element in a collection or array.

foreach ( itemType item in collection ) {
   ... statements ...
}
  C# VB JScript

The foreach loop is entered if there is at least one element in the group to enumerate. If so, the embedded statements are executed for each element in the group. When there are no more elements, the loop ends and control is passed to the statement after the foreach block.

The following example shows use of a foreach statement to display the CultureInfo names and currency formats for each supported culture in the .NET framework.

 Show me 

Below are links to further code examples that illustrate using the foreach loop in ASP.NET web forms.

Determining Selected Items in a CheckBoxList Control
Run Sample | View Source
WebControl ForeColor and BackColor Properties Example
Run Sample | View Source
DataGrid GridLines Property Example
Run Sample | View Source
More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note