Why does "nil" in a table breaks the ipairs for loop?

I noticed that

..., function() return end, ...

won’t break the table - why nil itself does?

I think you mean, why does ipairs not work on an array with nil in it. It’s because ipairs stops once it reaches a nil value in the array you gave it.

If you want to iterate through your array and your array has nil in it, you could use this for loop:

local arr = {17,58,nil,64,788}
for i = 1, #arr do
    print("arr["..i.."] = ",arr[i])
end

Just make sure you have a non-nil value at the end of your array or it will not count any nils at the end of your array, eg:

local incorrect = {10,23,40,nil,nil,nil}
local correct = {10,23,40,nil,nil,nil,0}
for i = 1, #incorrect do
    print(incorrect[i]) -- prints: 10, 23, 40
end
for i = 1, #correct do
    print(correct[i]) -- prints: 10,23,40,nil,nil,nil,0
end

But there’s one problem. There’s a zero getting printed which we don’t want, so we do this instead:

for i = 1, #correct - 1 do -- #correct - 1!
    print(correct[i]) -- prints: 10, 23, 40, nil, nil, nil
end

But let’s not forget. I’m not an expert. I recommend waiting to see what other people have to say.