Home

Basically there are two types of loops in asp, For and While loops.

For...next  Loop

Loops for a certain number of time that is predefined:
 

<%
For i=1 to 10
  Response.write i & "<BR>"
Next
%>

While...wend Loop

Loops until a certain condition is meet, in this case the loop runs as long as the variable i is less than 10. Here i is incremented by 1 to bring an effect similar to the For loop. In other situations the number of iterations can vary within the while block depending on the programming:
 

<%
Dim i
i=0

While i<10
  response.write i & "<BR>"
  i=i+1
Wend
%>

  

Do While...Loop

This example is same as the while/wend loop with a different syntax:
 

<%
i=0
Do While i<10
    response.write("Hello: " & i & "<HR>")
    i=i+1
Loop
%>

Do Until...Loop

Again a similar loop with a different syntax:
 

<%
i=0
Do Until i<=10
    response.write i & "<BR>"
    i=i+1
Loop
%>

[Download Sample Code]