lua-users home
lua-l archive

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


> I've been considering lua and playing with it
> from time to time but am confused about something...

Cool, hope you like it.

> Is there a way to make the counter/index variable
> used in the for loop accessible outside the for loop
> without having to set the outside var to the index
> at each iteration? Doing that makes for only as fast
> as while, and is generally annoying regardless.

Well, annoying is relative. I find it annoying when for indices aren't
local.

The short answer to your question is no.

The slightly longer answer is to try timing the difference between:

for i = 1, 1000000
  local j = F(i)
  x = i
end

and

local x
for i = 1, 1000000
  local j = F(i)
  x = i
end

You might find that the local x makes a big difference