At 12:10 AM +0100 4/15/06, Mark O'Neill wrote:
Now, aside from the obvious that DownTo is in reverse order are there any gains in using DownTo?

DownTo also allows you to avoid repeatedly calculating the loop termination point.

for i = 0 to UBound(MyArray)

Calculates UBound EVERY time through the loop


for i = UBound(MyArray) DownTo 0

Only calculates UBound prior to the first iteration through the loop

Now UBound isn't particularly expensive, so it might not matter much. However the benchmark example from earlier today had an expensive termination condition and so calculating it on every loop iteration made a BIG difference in overall speed. In that case you might choose to use DownTo, or just calculate the termination condition once and cache it.

dim z as integer = ExpensiveMethod()
for i as integer = 0 to z

Next

Regards,
Joe Huber
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to