Re: Labeled Loops?
Euler German wrote:
>
> > On 12 May 2008 at 17:01, Jeremy Cowgar wrote (maybe snipped):
>
> > Hm... what about:
> >
> > }}}
<eucode>
> > for a = 1 to 10 label "top" do
> > for b = 1 to 10 label "mid" do
> > while 1 do
> > if b = 3 then exit "top" end if
> > if a = 2 then continue "mid" end if
> > end while
> > end for
> > end for
> > </eucode>
{{{
> >
>
> I agree if all we need is "breaking" loop laces. But if I need to go
> to "Far Far Away" then probably we'd need "goto". The problem I see
> is that in an Euphorian way, labels should (must?) be declared prior
> to use, just like variables, so this would be a problem in most
> cases.
No, labels would neither be declared nor usable in anything but a exit or
continue. i.e.
while 1 label hello do
? hello
end while
You will get a compile error of an unknown variable hello. Their use in continue
and exit will be special uses and will search the loop stack for the
corresponding loop label, not a variable stack or anything.
>
> And Jeremy, just trying to understand the concept of "exit" and
> "continue" on the example above: continue "mid" exits the while loop
> and goes to next iteration of "mid" for...end for loop. OTOH, exit
> "top" exits the whole thing and code will continue execution after
> "top" for...end for loop, if any. Did I get it right? Sorry, but I'm
> getting these nouveaut=E9s quite slowly. :)
>
In the above example... exit "top" exits to the loop with the label "top".
continue "mid" continues with next iteration of the loop labeled "mid".
We would probably need a special label such as "all" or something that would
exit all loops.
--
Jeremy Cowgar
http://jeremy.cowgar.com
|
Not Categorized, Please Help
|
|