Looping in Classic ASP and VBScript

Last updated: August 27, 2026.

VBScript supports For...Next, For Each...Next, and Do...Loop. Choose a loop with a clear stopping condition.

<%
Dim i
For i = 1 To 5
    Response.Write "<p>Item " & i & "</p>"
Next
%>
<%
Dim key
For Each key In Request.QueryString
    Response.Write Server.HTMLEncode(key) & "<br>"
Next
%>

Ensure every Do loop can terminate and encode untrusted output before placing it in HTML.

admin

admin

Leave a Reply

Your email address will not be published.