Re: ex.exe hangs in a while loop

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

Thanks so much to Derek, Don, and Cuvier for their insights and replies.

You guys were absolutely right, I failed to adjust crsr's value properly
when doing the second "find()", so "value()" had no chance of succeeding
as it was given the wrong parameter.

But the problem with adjusting crsr to compensate for this (which could
be done as simply as "crsr += find('$', text[crsr+1..$])", is that the
loop uses "crsr > 0" as its true/false looping condition. So Derek's code
would work fine as long as the loop condition used temp instead of crsr,
and so the initial find() would need to be assigned to temp, too.

(BTW, this code is actually in a function that needs to return the values
of text (intact) and price. I just stuck it in main() in case someone
wanted to test the debugger issue--that is, if it is an issue.)

So, with thanks to the worldwide debugging team, the corrected code is:

incude get.e
procedure main()
  integer crsr, price, offset
  sequence text, t
  text = "/GRVY $.75 /GRVY $.75"
  price = 0
  offset = 0
  crsr = find('$', text)
  while crsr do
    t = value(text[crsr+offset+1..$])
    if t[1] = GET_SUCCESS then
      price += floor(t[2]*100) -- ensure truncating to an integer
    end if
  offset = crsr+1
  crsr = find('$', text[offset..$])
  end while
end procedure


However, I still find it odd that although my failed logic (trying to
code at 3 a.m. when I could barely focus on the keyboard) hung the debugger.
Shouldn't it just keep stepping me through the loop over and over?
Or is that because I was using the down arrow instead of the Enter key?

Thanks again, everyone!

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

Search



Quick Links

User menu

Not signed in.

Misc Menu