What is the best way to iterate through an array in Classic Asp VBScript?

Ronnie picture Ronnie · Aug 5, 2008 · Viewed 70.2k times · Source

In the code below

For i = LBound(arr) To UBound(arr)

What is the point in asking using LBound? Surely that is always 0.

Answer

Chris Farmer picture Chris Farmer · Aug 5, 2008

Why not use For Each? That way you don't need to care what the LBound and UBound are.

Dim x, y, z
x = Array(1, 2, 3)

For Each y In x
    z = DoSomethingWith(y)
Next