lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Oct 31, 1997 at 02:39:56PM -0200, Philippe Goutier wrote:
> >>I also miss, even more than for loops, break and continue as in C.
> >> I have already discussed the matter briefly with Roberto and he has
> >> some neat ideas on the subject. Since we are discussing about
> >> possibilities for the next version, why not discuss this also?

> One suggestion on the subject would be an extension to the C "break": a
> statement such as "break all" to exit all imbricated loops in just one
> operation.

I don't miss break and continue. I find their use ambigiuous, and anything
you can do with them, can be done with standard blocks easily.

I really prefer Java's incarnation of the "break" statement. It's a
combination of the break concept and a "goto". You have to specify a
destination for the break. Unless you use break in only one language and
use it frequently, the location you are going to break to is usually
ambigious IMO. The AT&T phone switch crash which occured several years
back ('89) here in the US was the result of a misinterpreted break
statement.

So, for example:

function a(x,y)
    local i = 0;

    while i < 5 do
       ..stuff..
       if g(i) then
           break exitfn;
       end
       if f(i) then
           while g(i) < 2 do
              ..stuff..
              if z(i) then
                   break exitfn;
              end
           end
       end
    end

  exitfn:
    print("we're done");
    
end


-- 
David Jeske (N9LCA) + jeske@chat.net