[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: breaking out of a while loop
- From: Duke Normandin <dukeofpurl@...>
- Date: Fri, 27 May 2022 19:57:55 -0600
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! **