1. Endless Loop
- Posted by Joseph Martin <jam at EXIS.NET> Apr 21, 1997
- 842 views
- Last edited Apr 22, 1997
Well I've done it again. I've gotten myself in a mess that only the gallant heroes of the Euphoria for DOS Mailing List can fix. Below is source for a routine I'm writing. I found out through the with trace statement that I'n an endless loop, BUT I can't figure out why. Someone PLEASE tell me where I'm misreading code. Thanks a bunch guys. with trace --test.ex include test.e sequence test, test_1 test = "Joseph Martin" trace(1) test_1 = nospace(test) printf(1, "%s", {test_1[1]}) --test.e global function nospace(sequence s1) sequence s2 atom space, n, x, y space = 1 n = 0 while space != 0 do space = find(32, s1) if space = 0 then return{s2} else n = space - 1 s2 = s1[1..n] x = space + 1 y = length(s1) s2 = s2 & s1[x..y] end if end while return{s2} end function ~~>Joseph Martin ~~>Personal: joe at cyber-wizard.com ~~>Web: jam.net at poboxes.com ~~>URL: http://users.exis.net/~jam/
2. Re: Endless Loop
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> Apr 21, 1997
- 814 views
- Last edited Apr 22, 1997
> Well I've done it again. I've gotten myself in a mess that only the > gallant heroes of the Euphoria for DOS Mailing List can fix. Below is > source for a routine I'm writing. I found out through the with trace > statement that I'n an endless loop, BUT I can't figure out why. > Someone PLEASE tell me where I'm misreading code. Thanks a bunch > guys. First of all, you need to change your two lines that say return{s2} to return {s1} Otherwise, you'll get an error if the original string contains no spaces. To fix the endless loop problem, change your line that says s2 = s2 & s1[x..y] to s1 = s2 & s1[x..y] Your problem was that the find() command kept searching the original string for spaces, and you never changed the original, so it kept finding the first space. Regards, Michael Bolin