lua-users home
lua-l archive

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


Nevin Flanagan wrote:
On Jan 13, 2010, at 9:18 PM, Joshua Jensen wrote:

I'm assuming (from the recent message referring to 'continue') that Lua 5.2 does not have a continue keyword?  I use continue almost every time I write a script, and it would sure be nice to have it an integral part of the language.  The continue patch works fantastic for me.

While I understand that the phrasing can be noticeably prettier and easier to maintain in some circumstances, is there something "if condition then continue end" does that "if not condition then rest_of_loop end" can't?

example 1:

for ... do
  if c1 then do
    ...
    if c2 then do
      ...
      if c3 then do
        ...
        if c4 then do
          ...
          if c5 then do
            ...
            if c6 then do
              ...
            end
          end
        end
      end
    end
  end
end

example 2:

for ... do
  if not c1 then do continue end
  ...
  if not c2 then do continue end
  ...
  if not c3 then do continue end
  ...
  if not c4 then do continue end
  ...
  if not c5 then do continue end
  ...
  if not c6 then do continue end
end

which example is more clean and more elegant looking? yep, the second one is.