In For Each ... Next loop like, for ... Next loop. Rather than the specified number of repeated statements,
Every name ... Next loops a repeating collection of objects (or each item) for each element in the array.
The following code fragment creates a Drop-down list to select one of the array elements:
Select Actionselect alltry it<%
Dim booktypes (7) ' Creates-a-i-array
Booktypes (0) = "Classic"
Booktypes (1) = "Information Books"
Booktypes (2) = "Fantasy"
Booktypes (3) = "Mystery"
Booktypes (4) = "Poetry"
Booktypes (5) = "Humor"
Booktypes (6) = "biography"
Booktypes (7) = "Fiction"
Dim Arrcars (4) ' creates second array
Arrcars (0) = "BMW"
Arrcars (1) = "Mercedes"
Arrcars (2) = "Audi"
Arrcars (3) = "Bentley"
Arrcars (4) = "Mini"
Sub createlist (Some_array) ' takes an array and creates Drop-down list
Dim i
Response.Write ("<select name=" "MyList" ">" & vbCrLf) ' VbCrLf stands for
Carriage return and line feeds
For each item in Some_array
Response.Write ("<option value=" & I & ">" & Item & "</option>" &
VBCRLF)
i = i + 1
Next ' Repeat the code and move on to the next value of I
Response.Write ("</select>")
End Sub
' Now let's call the Sub & print out we lists on the screen
Call CreateList (Booktypes) ' takes booktypes array as a argument
Call CreateList (Arrcars) ' takes arrcars array as a argument
%>