Library code snippets
Iterate Arrays with For Each
The most common technique for iterating the contents of an array is to use a For
Next loop and indicate the subscript for the array within the loop, like this:
<%
Dim strArray(3)
strArray(0) = "Paul"
strArray(1) = "John"
strArray(2) = "George"
strArray(3) = "Ringo"
Dim intCount
For intCount = LBound(strArray) To UBound(strArray)
Response.Write strArray(intCount) & "<br>"
Next
%>
But another approach is to use a For Each loop. This technique doesn't require
you to keep track on the subscript for each item, nor does it require you to
interrogate the LBound and UBound on the array. This approach is shown below:
<%
Dim strArray(3)
strArray(0) = "Paul"
strArray(1) = "John"
strArray(2) = "George"
strArray(3) = "Ringo"
Dim strItem
For Each strItem in strArray
Response.Write strItem & "<br>"
Next
%>
Related articles
Related discussion
-
Read eMails from Outlook express using ASP
by kumaravelu (1 replies)
-
Help to Call ASP function from onclick event in HTML to pass an array
by vka (0 replies)
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Variable In Vb.Net
by chia (0 replies)
-
ideas in building a captive portal
by sjranjan (2 replies)
Related podcasts
-
Scott Guthrie
Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.
When using For Each to iterate through a multidimensional array, how do you reference the other items?
This thread is for discussions of Iterate Arrays with For Each.