Re: For Each by brian
brian
Wed Aug 16 19:13:01 CDT 2006
I'm a little confused by what you've said--does this mean that this
code will always traverse the elements of the string in forwards order
(a to e) and print "abcde"?
x = Split("a,b,c,d,e", ",")
For Each c In x
Response.Write c
Next
And similarly, if x comes from a routine where I know how the elements
of the collection or array are ordered, then For Each will traverse the
elements in order? So in other words, these two are always equivalent
for an array x?
For i = 0 To UBound(x)
elt = x(i)
...
Next
For Each elt In x
...
Next
Dan wrote:
> If you are the source of the array data, then you have control in which
> order the elements will be added to the array. Example, if I split
> "Aa", "Bb", "Cc", "Aa" will always be index 0, "Bb" will always be
> index 1, etc. How you crawl the array is under your control; if you
> don't crawl it from index 0 to the upper bound index, then you wont
> have data returned as expected. If, however, you are not in control of
> the mechanism that provides you with the data (like you use a SQL, WMI,
> LDAP, etc. or whatever as a source), then your script has no control
> over how the data is delivered.