Re: Goto (Was Re: Open Source)

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

Matt Lewis wrote:
> 
> Juergen Luethje wrote:
> > 
> > I do not make it a religion. Please do not put words into my mouth.
> > I just say that it's obsolete in high-level languages. This is of
> > course only true if a language provides sufficient other possibilities.
> > For instance in Euphoria, it would be useful not only to have an 'exit'
> > statement, but also the possibility to write something like
> > 
> >    exit <number of levels>
> 
> I've often thought this, too, although that construct worries me.  What
> happens if the levels change?  Even if they don't change, it's not trivial 
> to figure out the target of that exit.  A label-based exit, OTOH, can be 
> very useful, and explicit.
> 
> For example, perl allows you to name a block (which could be a while/for/etc)
> and to use the next/last operators along with the block name:
> 
> <a
> href="http://en.wikipedia.org/wiki/Perl_control_structures">http://en.wikipedia.org/wiki/Perl_control_structures</a>
> 
> A euphorian implementation might look like:
> }}}
<eucode>
> :mainloop for i = 1 to n do
>     ...
>     :jloop for j = 1 to m do
>         ....
>         if foo then 
>             exit :mainloop 
>         end if
>         while foo > 5 do
>             ...
>             if bar then
>                exit :jloop
>             end if
>             ...
>     end for
> end for
> </eucode>
{{{

> That keeps the labels firmly associated with their proper loops.  It 
> makes the goal very clear, although at the expense of clarity of where
> you're going:
> }}}
<eucode>
> 
> for i = 1 to n do
>     ...
>     for j = 1 to m do
>         ....
>         if foo then 
>             goto :mainloop 
>         end if
>         while foo > 5 do
>             ...
>             if bar then
>                goto :jloop
>             end if
>             ...
>     end for
>     :jloop
> end for
> :mainloop
> </eucode>
{{{

> I can see benefits to both ways, though I think I would prefer keeping 
> them associated with the loop.  It's also how exits work right now.
> 
> Matt

Or maybe, a more restricted solution that doesn't include labels:
   exit <for-loop variable>
The for-loop variable would be optional.

- Fernando

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

Search



Quick Links

User menu

Not signed in.

Misc Menu