>Hi George,
>in a heavyly used function I'ld see here a reasonable case for "exit"
>
>DO WHILE lnfirst < lnlast
> lnmid = INT((lnfirst + lnlast)*0.5)
> Do Case
> case tsearchfor > tarray[lnmid]
> lnfirst = lnmid + 1
> case tsearchfor < tarray[lnmid]
> lnlast = lnmid - 1
> otherwise
> exit
> EndCase
>ENDDO
>
>
>which not only removes the need for the "found" variable in the loop
>but also eliminates the redundant check in the original codes
>first if and the do while by using the argument starting "exit".
>
>To my eyes this is also better readable (I realize this is quite personal)
>and probably faster in most cases, even if do case is slower than a single if.
>(Haven't checked the factor for quite some time on this one...).
>
>still, if it is really heavyly used, using a hash table or btree
>might be better than optimizing a bsearch, even if the loop count
>won't exceed thirtysometing <bg>
>
>my 0.02 EUR
>
thomas,
The reason that the llfound variable is used is that it allows for a "soft search" which can be quite handy. The above doesn't.
George
Ubi caritas et amor, deus ibi est