lua-users home
lua-l archive

Re: proposal: state machine syntax also usable for continue /nested break

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


?What about a loop like this one:
for _,vv in pairs(t) do
 for _,v in pairs(vv) do
 break :_: end
 end
end
As much as I hate magic-ing up the declaration of local variables (allowing you to break to the next statement after the local was declared?), re-using those semantics would make the answer pretty clear (the inner one). The downside here is that you wouldn't be able to refer ahead to labels (since locals aren't visible before they're declared), but you could fake it:
for i=1,100 do
 local continue=false
 if not continue then
 --snip loop content--
 --continue scenario
 continue=true
 break i
 end
end
-----Original Message----- From: David Manura Sent: Thursday, January 27, 2011 9:09 PM Newsgroups: gmane.comp.lang.lua.general
To: Lua mailing list
Subject: Re: proposal: state machine syntax also usable for continue /nested break
On Fri, Jan 28, 2011 at 12:03 AM, David Manura <dm.lua@math2.org> wrote:
I don't local variables can completely replace labels in the above
proposal (as opposed to [1]). However, my above suggestion for
implicitly naming variables could incorporate the loop variable name
in the label. Therefore, :forfor: could be replaced with :kk: .
err, correction: don't -> don't think; naming variables -> naming
labels. In other words, this would be consistent with the proposed
semantics:
for kk, vv in pairs(tt) do
 for k, v in pairs(t) do
 if condition1 then break end -- same as `break :k:`
 if condition2 then break :continue: end
 if condition3 then break :redo: end
 if condition4 then break :kk: end
 end
end

AltStyle によって変換されたページ (->オリジナル) /