ASP — Loops
For Loop
<%
Dim i
For i = 1 To 10
Response.Write(i & "<br>")
Next
%>
For Each
<%
Dim arr(2)
arr(0) = "Apple"
arr(1) = "Banana"
arr(2) = "Cherry"
Dim fruit
For Each fruit In arr
Response.Write(fruit & "<br>")
Next
%>
Do While
<%
Dim i
i = 1
Do While i <= 10
Response.Write(i & "<br>")
i = i + 1
Loop
%>
Do Until
<%
Dim i
i = 1
Do Until i > 10
Response.Write(i & "<br>")
i = i + 1
Loop
%>
Exit For
<%
Dim i
For i = 1 To 100
If i > 10 Then
Exit For
End If
Response.Write(i & "<br>")
Next
%>
Mini Practice
- Use For loop
- Use For Each
- Use Do While
- Exit loop early
Up Next
Continue with Procedures — subroutines and functions.
Related Topics
Frequently Asked Questions about Loops
What is Loops in ASP?
Loops is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Loops?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Loops.
Why is Loops important in ASP?
Loops is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.