asp-classic Looping For Loop

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

In classic ASP we can specify a for loop with the for keyword. With the for statement we need the next statement which will increment the counter.

For i = 0 To 10
    Response.Write("Index: " & i)
Next

The step keyword can be used to changed the how the next statement will modify the counter.

For i = 10 To 1 Step -1
    'VBS Comment
Next

To exit a for loop, use the Exit For statement

For i = 0 To 10
    Response.Write("Index: " & i)
    If i=7 Then Exit For 'Exit loop after we write index 7
Next

We can also use a For...Each loop to perform a loop through a series of defined elements in a collection. For instance:

Dim farm, animal
farm = New Array("Dog", "Cat", "Horse", "Cow")
Response.Write("Old MacDonald had a Farm, ")
For Each animal In farm
    Response.Write("and on that farm he had a " & animal & ".<br />")
Next


Got any asp-classic Question?