lua-users home
lua-l archive

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


On Wed, 27 Feb 2008 11:32:27 -0300, Roberto Ierusalimschy wrote:
> Continue, on the other hand, is a real feature. (It even changes the
> syntax and the lexical.)  Our main concern with "continue" is that there
> are several other control structures that (in our view) are more or
> less as important as "continue" and may even replace it. (E.g., break
> with labels [as in Java] or even a more generic goto.) "continue" does
> not seem more special than other control-structure mechanisms, except
> that it is present in more languages. (Perl actually has two "continue"
> statements, "next" and "redo". Both are useful.)
[1]

We may think of break, continue, redo, and break with labels all as a
generalization of "break N", slightly generalizing PHP's and
especially Idle's "break N" [2,3]:

  -- begin scope 3
  for x=1,10 do
    -- begin scope 2
    m()
    -- begin scope 1
    for y=1,10 do
      -- begin scope 0
      if a() then break -3 end -- same as goto "begin scope 3" (redo outer loop)
      if b() then break -2 end -- same as goto "begin scope 2" (redo
outer loop iteration)
      if c() then break -1 end -- same as goto "begin scope 1" (redo loop)
      if d() then break -0 end -- same as goto "begin scope 0" (redo
loop iteration)
      if e() then break 0 end -- same as goto "end scope 0" (break
loop iteration -- i.e. continue)
      if f() then break 1 end -- same as goto "end scope 1 (break loop
-- i.e. "break")
      if g() then break 2 end -- same as goto "end scope 2" (break
outer loop iteration -- i.e. continue outer)
      if h() then break 3 end -- same as goto "end scope 3" (break
outer loop -- i.e. break outer)
      -- end scope 0
    end
    -- end scope 1
    n()
    -- end scope 2
  end
  -- end scope 3

Note: This also shares some resemblance to `level` in `error(message, level)`.

[1] http://lua-users.org/lists/lua-l/2008-02/msg01183.html
[2] http://idle.thomaslauer.com/IdleFAQ.html
[3] http://www.python.org/dev/peps/pep-3136/
[4] http://lua-users.org/wiki/ContinueProposal