lua-users home
lua-l archive

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


>It is often helpful to read the manual. Lua is a small language and
>the manual is small as well.
Sorry for disturbing you.
I have studied the differences between "ipairs" and "pairs".
But I totally forgot them when I saw such outputs.

I will do more work before asking for help later.

Best regards
Sunshilong

On Thu, Oct 15, 2020 at 5:43 PM Robert Burke <sharpobject@gmail.com> wrote:
>
> On Thu, Oct 15, 2020 at 6:11 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> > Why does the output of "for in pairs" is right whereas the output of
> > "for in ipairs" is wrong?
>
> The question is "Why, when I give ipairs a table that has a nil value
> at t[2], does it stop iterating? And why, when I give it a table that
> has a nil value at t[1], does it not even iterate over one entry?"
>
> The manual says:
> ipairs (t)
> Returns three values (an iterator function, the table t, and 0) so
> that the construction
>      for i,v in ipairs(t) do body end
> will iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to
> the first nil value.
> https://www.lua.org/manual/5.3/manual.html#2.2
>
> It is often helpful to read the manual. Lua is a small language and
> the manual is small as well.