在ASP中,遍历数组通常使用For
循环或For Each
循环。以下是两种方法的示例:
方法1:使用For
循环遍历数组
<%
Dim myArray(5)
myArray(0) = "Apple"
myArray(1) = "Banana"
myArray(2) = "Cherry"
myArray(3) = "Date"
myArray(4) = "Elderberry"
myArray(5) = "Fig"
For i = 0 To UBound(myArray)
Response.Write myArray(i) & "<br>"
Next
%>
方法2:使用For Each
循环遍历数组
<%
Dim myArray(5)
myArray(0) = "Apple"
myArray(1) = "Banana"
myArray(2) = "Cherry"
myArray(3) = "Date"
myArray(4) = "Elderberry"
myArray(5) = "Fig"
Dim item
For Each item In myArray
Response.Write item & "<br>"
Next
%>
在这两个示例中,我们首先创建了一个包含6个元素的数组myArray
,并为每个元素分配了一个值。然后,我们使用For
循环和For Each
循环分别遍历数组并输出每个元素的值。