Re: ex.exe hangs in a while loop

new topic     » goto parent     » topic index » view thread      » older message » newer message

olddog wrote:
> 
> Oops! Punched a wrong button half way thorugh my post:
> 
> My 2.5 interpreter hangs (even the trace() debugger hangs) with this code:
> 
> }}}
<eucode>
> incude get.e
> procedure main()
>   integer crsr, price
>   sequence text, t
>   text = "/GRVY $.75 /GRVY $.75"
>   price = 0
>   crsr = find('$', text)
>   while crsr do
>     t = value(text[crsr+1..$])
>     if t[1] = GET_SUCCESS then
>       price += t[2]*100
>     end if
>     crsr = find('$', text[crsr+1..$])
>   end while
> end procedure
> </eucode>
{{{

> 
> If text only equals "/GRVY $.75" then it works fine, but as it is above
> it hangs (the debug trace locks up on the end while statement).
> 
> Workarounds, anyone?

I can see a problem. The second find() gives a result as an offset from the
first '$' and you don't adjust that to be an offset from the start of the text.
Try this instead...

    temp = find('$', text[crsr+1..$])
    if temp then
        crsr += temp+1
    end if
  end while

The details...
On the first find() it returns 7. So the second find() looks at the slice
starting at 8 which returns 10. This is the offset from the start of the slice,
not the start of the text. To adjust it you need to add the slice start position
to the returned value, making it 18.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu