lua-users home
lua-l archive

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


On Sat, 28 May 2022 02:53:21 +0100
Marcus Mason <m4gicks@gmail.com> wrote:

> > A “smart” alternative would be this loop:
> >  while true do
> >    local k = next(t)
> >    if not k then break end
> >    t[k] = nil
> >  end
> 
> The reason this code works is because `next` returns `nil` when
> there is no key. If you check my previous post you'll see the
> alternative condition you'd need to write this style of loop.

Got it!

> .... I think your original code
> with the condition in the while loop – the one which starts
> `while bottle_count ~= 0 do` – is fine, and I'm not sure there's
> a performance difference here either.

Performance will come later for me. Thanks for the input!

-- 
Duke
** Bottom-posting, text-only is the netiquette way! **