Loop Statements in ASP.NET

Loop Statements:

Loop Statements are used to execute and repeat a block of statements depending on the value of a condition. There are three types of Loop Control Statements in ASP.NET:

1. For Loop: These loop requires a start number and an end one. It increments the value of its counter automatically.
Example:

Dim Counter as Integer
For Counter = 1 To 3
Response.Write("The value of loop Counter is " & Counter & "
"

2. While Loop: This loop will execute as long as the condition given is true. It does not increment the value of its counter automatically.
Example:

<%
Dim j as integer = 1
While (j<=50)
response.Write(i)
response.Write("SRK")
response.Write("
")
j= j+ 1
end while
%>

 

3. For Each Loop: If you work with a collection or an array, then for each loop is very useful.
Example:

Dim Dog As String
Dim Cats(1) As String
Cats(0) = “Tom”
Cats(1) = “Jerry”
For Each Dog In Cats
Response.Write(Dog & "")