lua-users home
lua-l archive

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


Although 'local' does make a nice difference with while,
it doesn't really with this for example. Even with the
x=i, it is pretty much the same speed as without, and
still plenty faster than while...

However, I would like to know why... what does it mean?
And what is the rationale behind it especially when it
makes things cryptic for the non-programmer users...

  local x=-1
  for i=1,10000000 do
    i = F(i)
    x = i
  end

That's too much for users I think, is there any solutions
that makes sense, which is not twice as slow like 'while' ?

Ideally, I would just be able to ignore the variable x.

--- In lua-l@y..., RLake@o... wrote:
> 
> > 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