lua-users home
lua-l archive

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


Reasons against it.

First
It will break existing code in a malicious way.

for k, _ in pairs( foo )
do
   bla
   do
      bla
      if condition
      then
         break
      end
   end
end

this code would have suddendly quite different behaviour with your suggestion applied.#

Second
it can be done with goto.

do
  goto something
  local x = "you'll never see me"
  print(x)
end
::something::
print("something")

Third
We have already a nasty overlap between goto and break doing essentially the same thing (while continue is not allowed to be the essentially same thing for those who would find that convenient). No need to make the overlap worse.


On Thu, Aug 28, 2014 at 4:17 AM, Thiago L. <fakedme@gmail.com> wrote:
It would be cool if you could use break with do ... end for some sort of "safe goto"

Example:

do
break
local x = "you'll never see me"
print(x)
end
print("something")

Would print "something"

In 5.2+ we have this:

goto x
local x = ""
::x::
print("something")

But it errors instead of doing the scoping stuff you can do with do ... end

(This is probably not something for lua 5 but for lua 6 if/when we get it... it would probably be less harmful to change goto so that it does an implicit do ... end scoping thingy)