lua-users home
lua-l archive

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


On Wednesday 06, David Manura wrote:
> On Wed, May 6, 2009 at 5:14 PM, Alexander Gladysh wrote:
> > Today I'm benchmarking iterating a table with ipairs vs. numeric for:...
> >   for i = 1, #t do
> >     if v == nil then
> >       break
> >     end
> >   end
> > end
> > ...
> >         7       [35]    GETGLOBAL       5 -2    ; v
>
> What's v?  Normally, the equivalent numeric loop would loop like
>
>   for i = 1, #t do
>     local v = t[i]
>   end

Both the do_loop_numfor and do_loop_while functions exit after the first 
iteration.

The while loop method is broken, since it doesn't initialize the 'i' variable 
to 1.

-- 
Robert G. Jakabosky