On Apr 15, 2006, at 8:32 AM, Mark O'Neill wrote:
On 15 Apr 2006, at 00:26, Seth Willits wrote:
The UBound is only calculated once with the DownTo.
Wow, really? In which case, when is it ever a good idea to use "to"
instead of DownTo?
What happens is the following. In the expression
for x from M to N,
the expression N is evaluated at the top of each loop. This has two
consequences. First, the time required to evaluate N is part of the
execution speed of the loop. Storing the ending value in a local
variable gives best performance. I have found that using UBound is
about as fast as storing its value in a local variable. The second
consequence is that N may evaluate to different values as the loop
progresses. This is a source of hard-to-find bugs. Storing the
value of N in a local variable and using this as the ending value
avoids such side-effects.
Charles Yeomans
_______________________________________________
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>