lua-users home
lua-l archive

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


It was thus said that the Great Lorenzo Donati once stated:
> 
> Of course you can litter your nested loops with something like
> 
> if some_condition then goto BAIL_OUT end
> 
> but this code can be completely understood only knowing where the 
> BAIL_OUT label is placed. It could be placed at the end of the nested 
> loops matrioska structure:
> 
> for ...
>  for ...
>   for...
>   end
>  end
> end
> ::BAIL_OUT::

  If I'm doing this, then I would restructure the code to be:

	-- existing code

	local function foo()
	  for ...
	    for ...
	      for ...
	        if somecondition then
                  return
		end
	      end
            end
	  end
	end
	
	foo()

  I would do the same to make up for the lack of continue:

	local function foo()
	  while somecondition do
	    ...
	    if somecondition then
	      return foo() -- my "continue" is here
	    end
	    ..
	  end
	end

	foo()

  Remember, Lua can have nested functions.

> But you can't be sure until you check it. And this could be 
> annoying/error prone if that nested structure is several editor page 
> long (I assume you have a good reason to have such a deeply nested 
> structure spanning so much code, and that code cannot be refactored in a 
> more readable way avoiding the nesting and maintaining the same efficiency).
> 
> OTOH, the statement:
> 
> if some_condition then break 3 end

  And later, that code is embeded one layer deeper, and now your "break 3"
is causing some issues because it may not be going where you think it's
going.  I'm not a fan of the "break 3" option.

  -spc