lua-users home
lua-l archive

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


Alexander Gladysh wrote:
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.

I'd say neither are clean and elegant looking. Such complex loop
bodies are to be refactored. If you can't refactor it to a set of
functions due to performance considerations, then elegance should not
be issue.

The second form is clearer especially if you are writing code with lots of validation stages or interlocks. "Refactoring" or hiding a bunch of stages in a separate function just so the loop looks cute isn't always the right solution. continue, like goto, is often misunderstood and under appreciated.