lnresult = 0 DO WHILE lnfirst < lnlast ... ENDDO IF tsearchfor = tarray[lnmid] THEN lnresult = lnmid ELSE IF llsoftsearch THEN lnresult = lnlast ENDIF ENDIF RETURN lnresultwhile some would call my probable favorite "too tricky"
LOCAL lnfirst, lnlast, lnmid, lnFoundExact lnfirst = 1 lnlast = ALEN(tarray, 1) * INTENDED: Local, but no init for lnFoundExact DO WHILE m.lnfirst < m.lnlast lnmid = INT((m.lnfirst + m.lnlast)*0.5) Do Case case m.tsearchfor > tarray[m.lnmid] lnfirst = m.lnmid + 1 case m.tsearchfor < tarray[m.lnmid] lnlast = m.lnmid - 1 otherwise lnFoundExact = m.lnMid exit EndCase ENDDO return iif(vartype(m.lnFoundExact)=="N", m.lnFoundExact, ; iif(m.llsoftsearch, m.lnLast, 0))I still believe "exit" enhances this particular code -