lua-users home
lua-l archive

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


On Thu, Jul 21, 2011 at 4:04 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> On the other hand, if a loop and a conditional, or nested loops,
> have the same body, I write as a habit
>    for i=1,n  if x[i]~=0
>        -- (body)
>        end end

I also commonly do things like

for k=1, 10 do
for j=1, 10 do
for i=1, 10 do
  f(i, j, k)
end end end

Replacing `end end end` with `ennnd` or (preferably) `end3` is not
going to gain much.  There was a Metalua blog post some type ago that
offered something similar [1]:

  for i=1,n if x[i] ~= 0 do
    -- body
  end

There is also some relationship here to list comprehensions [2]:

  for _, i in ipairs(comp'i for i=1,n if x[i] ~= 0') do
    -- body
  end

[1] http://metalua.blogspot.com/2008/02/syntax-experiments.html
[2] http://lua-users.org/wiki/ListComprehensions