This maybe closer to what your getting at, I didn't add any lines, just changed the condition of the DO WHILE:
lparameters lcCode, lcPath
lnWA = select()
select 0
use (iif(empty(lcPath), '', lcPath) + 'words')
lcCode = strtran(lcCode, chr(9), space(5))
lcCode = strtran(lcCode, '&', '&')
lcCode = strtran(lcCode, '<', '&lt;')
lcCode = strtran(lcCode, '>', '&gt;')
local laLines[1], lcReturn
alines(laLines, lcCode)
lcReturn = '<b><pre>'
for lnI = 1 to alen(laLines)
lcLine = laLines[lnI]
if empty(alltrim(lcLine))
lcReturn = lcReturn + chr(13) + chr(10)
loop
endif
if upper(alltrim(lcLine)) = '*' or;
upper(alltrim(lcLine)) = 'NOTE'
lcLine = '<font color=green>' + ;
lcLine + '</font>'
lcReturn = lcReturn + chr(13) + chr(10) + lcLine
loop
endif
local lcFormat, lnFormatLength, lcFL, ;
lcRW, lnRWLength, lnStartRW, lnOccurance
lcFormat = '<font color=blue>'
lnFormatLength = len(lcFormat)
lcFL = ' '+ upper(trim(chrtran(lcLine, ':;./\<>+=-}]()#', space(15)))) + ' '
local lcDoubleAmp, lnStartComment
lcDoubleAmp = '&amp;&amp;' &&This is to test our function
lnStartComment = at(lcDoubleAmp, lcLine)
if lnStartComment > 0
lcLine = stuff(lcLine, lnStartComment, 0, '<font color=green>') + ;
'</font>'
endif
scan
wait window nowait 'Line ' + alltrim(str(lnI)) + ;
' RW ' + alltrim(str(recno()))
lcRW = ' ' + alltrim(REVWORD) + ' '
lnRWLength = len(lcRW) - 2
lnOccurance = 1
lnStartRW = at(lcRW, lcFL, 1)
do while lnStartRW > 0 and (lnStartComment = 0 or lnStartRW < lnStartComment)
lcLine = stuff(lcLine, lnStartRW, 0, lcFormat)
lcLine = stuff(lcLine, lnStartRW + lnFormatLength + lnRWLength, 0, '</font>')
lcFL = ' '+ upper(trim(chrtran(lcLine, ':;./\+=-}]()<>', space(14)))) + ' '
lnOccurance = lnOccurance + 1
lnStartRW = at(lcRW, lcFL, lnOccurance)
enddo
endscan
lcReturn = lcReturn + chr(13) + chr(10) + lcLine &&Another InLine Test to use
endfor
lcReturn = lcReturn + '</pre></b>'
use
select (lnWA)
return lcReturn