lua-users home
lua-l archive

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


On 22.01.2011 15:23, steve donovan wrote:
The best answer is by Roberto, quoted by David Manura in this post:
http://lua-users.org/lists/lua-l/2010-11/msg00479.html

That's a real deal. I find 'continue' and 'break N' both very useful in certain situations. I think there also were situations where I wanted 'continue N' that would act similar to 'break N'. 'Redo' and 'continue n' with 'n' indicating the number of iterations to skip are useful too...

Now, to the readability.
The first thing is that 'break' and 'continue' must be separate keywords for the sake of readability.

I don't think 'break N' would worsen readability much compared to standard 'break'. You already have to get over one or two ends of IF's now to find the end of the loop. In many cases nested loops come one right after another and 'break N' would be almost as readable as simple 'break'. Actually, when 'break N' is needed, it improves readability, because work-arounds used instead of just shadow the logic.

I like the suggestion of labeled loops, it's certainly more readable, but it's a serious syntax extension. I gravitate towards something like this syntax:
for y = 1,10 do
  for x = 1, 10 do
    break 'y'
  end 'x'
end 'y'
The stringy labels should prevent any collisions with operators that follow.


Overall, I consider simple 'continue' to be a safe ground. Any readable more sophisticated solution I can think of would still include the 'continue' statement.


--
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru