lua-users home
lua-l archive

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


I've another idea how to capture full loop functionality, in a way
I've not yet seen in another language.
1) continue as new keyword - better just get over with it, than to
overload existing keywords with new functions that are contrary to
their everyday meaning - like break as continue..
2) let continue take an optional argument to how often call the
iterator for for loops.

continue   -- like in C, do next iteration
continue 1 -- synonymous to continue - call iterator once
continue 0 -- goes to start of loop calling the iterator 0 times - "redo"
continue 2(or more) -- calls the iterator twice, skiping one

continue -1 -- error! cannot reverse iterate (with n..m..k loops this
might theoretically work, but not with genericf for loops)

thinking about e.g. argument parsing, this continue X would be a dream!


On Fri, Nov 19, 2010 at 8:20 AM, Axel Kittenberger <axkibe@gmail.com> wrote:
> wait, +0 is something different than -0? No please not.
>
> BTW: with a continue and multilevel break, i consider "redo" not a an
> essential feature of same importance, since with these 2 constructs,
> redo can really be emulated very simply.
>
> for i=1,10 do repeat
>   if a(i) then
>      break -- next i / continue
>   end
>   if b(i) then
>      break 2 -- break for loop
>   end
>   if c(i) then
>      continue -- redo with same i
>   end
> untilt true end
>
>
> On Fri, Nov 19, 2010 at 5:25 AM, David Manura <dm.lua@math2.org> wrote:
>> 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
>>
>>
>