> I found myself using this trick very often but I have no idea what
> price in terms of performance and memory consumption it costs
> (creating closures just for a single use, etc). Is it a good idiom and
> are there any alternatives??
You can also use a 'do' block:
--breaking from nested loops
t={ {0,1,2,3,4}, {10,11,-12,13,14} } -- two dimensional array
do
for i=1,#t do
for j=1,#t[i] do
if t[i][j]<0 then return end --break out of all loops if negative
print(i,j,t[i][j])
end
end
end
It might be not be cheaper, but it looks better IMHO. :)
Cheers,
Luis.