1. Re: re-eval loops
Kat wrote:
>
> Matt Lewis wrote:
>
> > Matt,
> >
> > A suggestion/request to make a difference from Eu:
> >
> > for urlloop1 = 1 to length(newsurls) do
> >
> >
> > I again got bit by the length() being evaluated only once, and not
> each time the line
> > is run over. In my case, i add to the nested sequence newsurls, so it
> properly
> > should grow as the program runs. But the length is tested only once,
> and locks
> > in the preliminary value, so the db isn't growing. This is something
> i often
> > haveto get around somehow.
>
> Luckily, with goto, i can now get past this headache in several ways,
> of *my* choosing. I easily recoded the for-loop (while-loop was as bad) to be
> a repeat-until loop (which Eu doesn't have), with *all* the important loop
> vars
> evaluated on *every* loop. I now have the following, and it runs nicely.
> }}}
<eucode>
> -- loop thru them --
>
> if length(newsurls) then -- got any?
> --for urlloop1 = 1 to length(newsurls) do -- this bites
>
> urlloop1 = 1 -- do it manually, got at least 1 if we got this far
> :"loopnewsurls" -- we can loop back to here
>
> == munging code goes here ==
>
> -- the following is a repeat-until loop!
> if urlloop1 < length(newsurls) then -- reached the end yet?
> urlloop1 += 1 -- nope, there's more, so increment
> goto "loopnewsurls" -- and loop up to the next index
> end if -- urlloop1 < length(newsurls) then
>
> --end for --urlloop1 = 1 to length(newsurls) do -- this bites
> end if -- if length(newsurls) then -- got any?
> </eucode>
{{{
>
> Vincent wrote:
>
> > Hi there... I don't think there needs to be any more loop methods.
> > "while" and "for" are good enough.
>
> I asked for "repeat-until" loops in the past, and RDS declined. I asked for
> "goto" so i can make my own, and RDS declined.
>
> All praise to "goto" for ease of coding around bugs, idiosyncrasies,
> and making *simple* and basic structures that don't exist in RDS's Eu!
>
> Kat
>
> <[ This message has been forwarded by Vincent on behalf of Kat. ]>
Hey, why not use "while" instead of "for"?
It solves the problem without much hassle.
Example:
---- EUCODE (not tested)----
integer i
i = 1
while 1 do
if i > length(x) then
exit
end if
.... body of code
i += 1
end while
----- EUCODE END ----
This way, you can even exit in the middle of your code.
Regards