Re: Labeled Loops?
> On 12 May 2008 at 20:01, Jeremy Cowgar wrote (maybe snipped):
> 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.
>
>
> }}}
<eucode>
> while 1 label hello do
> ? hello
> end while
> </eucode>
{{{
>
> 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.
>
Hmmm, I got that. What I was saying "labels" would be part of while
and for laces *only*, that is, there'll be no outsiders that could be
used, say, for a "goto". Let me go a little further and play the
Devil's lawyer.
while 1 label hello do
...
if FALSE exit hello end if
...
end while
while 1 label hi do
...
if FALSE exit hello end if -- note "hello" in place of "hi"
...
end while
I would expect an error as "hello" isn't part of the second loop
stack, right? Maybe I'm exaggerating but that is why I don't like
labels. They can be easily misplaced. If escape conditions are to be
constrained to loops I see very little benefit of using it.
> >
> > 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".
>
Do you mean it'll restart "top" loop from 1? I'm a bit confused. I
understand "continue" very clearly. It means (to me) "forget this
one, but continue trying with next". But what I get from "exit" is
just "left this and go ahead".
> We would probably need a special label such as "all" or something that
> would exit all loops.
>
I don't know, really. You guys are light-years ahead of me. But it
looks more as shortcuts to gain nanoseconds or ways to get into a
hole an emerge in a parallel dimension.
Please, don't take this as criticism. I want to contribute with my
lack of knowledge so Euphoria still be attractive to newcomers.
Best,
Euler
--
_
_| euler f german
_| sete lagoas, mg, brazil
_| efgerman{AT}gmail{DOT}com
|
Not Categorized, Please Help
|
|