lua-users home
lua-l archive

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




2011/1/28 dcharno <dcharno@comcast.net>
On 01/27/2011 11:42 AM, Roberto Ierusalimschy wrote:
  while cond do
    do :process_item:

                    break :process_item:

    end
  end

Do you really need the extra : after the label since both do and break are keywords?


There are several details that could change (other mark instead
of colons, whether the label after break needs marks, whether an
optional [or mandatory] label could be added after the corresponding
'end', etc.), but the basic idea would not change much.

Maybe the label is attached to the end keyword since (visually) it indicates where you are going.

   while cond do
     do

        break : process_item

     end : process_item
   end

That would allow you to label a break out of a while loop:

  while cond do

     break : while_end

  end : while_end

or a for loop:

  for i=1, 10 do

    break : for_end

  end : for_end

maybe we can use a variable name as label:

for i = 1, 10 do
    for j = 1, 20 do
        ....
        break i
    end
end

local cond
while cond do
    while ... do
        break cond
    end
end