[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: continue continued, with break N
- From: Nilson <nilson.brazil@...>
- Date: Sat, 20 Nov 2010 08:54:10 -0200
On Sat, Nov 20, 2010 at 1:46 AM, David Manura <email@example.com> wrote:
> On Fri, Nov 19, 2010 at 2:20 AM, Axel Kittenberger <firstname.lastname@example.org> wrote:
>> wait, +0 is something different than -0? No please not.
> Another numbering scheme may be better, but I think now that numbered
> scopes are less readable/decipherable than named scopes.
> Interestingly, Lua already has named scopes: they are called lexical
> variables. That leads to this proposal:
> for x=1,10 do
> local cont -- dummy variable
> for y=1,10 do
> if f(x,y) then break x end -- jump to end of x scope (i.e.
> break outer loop)
> if g(x,y) then break cont end -- jump to end of cont scope
> (i.e. continue outer loop)
> which may warrant serious consideration. It opens up some other
> possibilities too, if the language designer chooses to allow it:
> local s
> if a() then break s end -- break out of non-loop blocks too.
> function f()
> local x
> return function()
> break x -- could this even be allowed? (break across functions)
What about "tagged blocks" as an alternative to goto. (similar to Ada exit)?
You can use with any command that creates a block - if, while, repeat,
for, do or even a function.
and with the end to inform the compiler what it closes (avoids
inconsistent end comments) .
do :regular -- may follows while, repeat, for etc.
while cond1 do
if cond2 then break :regular end -- or exit :regular (I prefer)
- error handling
if :test1 cond then
if cond2 then
if cond3 then break :test1 end -- exit :test1;
The tag in while or for could be after the do.
while cond do : tag
or after the while
while :tag cond do
Well, since we are talking about changes in Lua syntax, another simple
and useful change could be
the creation of "conditional jumps" that does not need of "then" and
"end" and never produces a "I forgot to create the block so a later
second command always be executed" syndrome because the second command
will never be executed after the "jump".
if cond return x
if cond break
if cond continue
while true do -- I prefer the "loop" keyword
-- do some initialization
if cond break
-- main code
function f (val1, val2)
if not test(val1) return 'error ...'
-- rest of code