Search code examples
lualua-table

How to make a table with 100 values but with increasing values?


My professor taught me this (below), for creating a 10 numbers table, but

   v = {}
    for i = 1, 10 do
    v[i] = i
    end

    print(v[3])

(the output will get me 3, as expected)

why do I recieve "nill" if I try doing this? (bellow)

v = {}
for i = 1, 10, 2 do
v[i] = i
end

print(v[42])

As you can see, I was trying to make a table like this

v = {1,3, 5, 7, 9}

Why it is not working? :(

<3


Solution

  • You're filling only the odd-numbered positions.

    Try

    for i = 1,5 do
      v[i] = 2*i-1
    end