Can someone explain why this code does not work for me, and also how to fix it:
local a, b, c, d, e = "one", "two", "three", "four", "five"; local f, g, h; --Nil values local i, j, k = "six", "seven", "eight" local l, m local t = {a,b,c,d,e,f,g,h,i,j,k,l,m} local nilCounter = 0 print("Size of table: " .. #t); for i = 1, #t do if (t[i] == nil) then nilCounter = nilCounter + 1 end end print("Number of nil in the table: " .. nilCounter);
Expected Output:
Size of table: 13
Number of nil in the table: 5
Actual Output:
Size of table: 5
Number of nil in the table: 0
For some reason, lua doesn’t seem to recognize the nil values in the table, how would I get it to recognize nil values?