Go to: Articles List
Part 1 | Part 2 | Part 3 | Part 4
When you want to loop through an array or something else, the For loop
is often the easiest way to do this. The syntax for the For loop is:
For CounterVar = FromCount to EndCount
'what you want to do
Next
And now for an example:
For i = 1 to 5
Response.Write("i=" & i & "<br>")
Next
Result:
i=1
i=2
i=3
i=4
i=5
Here is another example looping through an array and printing
out it's contents, element by element.
myArr = Array("apples","oranges","grapes","peaches","watermelon")
For i = 0 to 4
Response.Write("myArr(" & i & ") = " & myArr(i) & "<br>")
Next
Result:
myArr(0) = apples
myArr(1) = oranges
myArr(2) = grapes
myArr(3) = peaches
myArr(4) = watermelon
Remember that arrays in ASP start with 0.
|
|
|
|