I can't use a table element as a counter variable for the for loop

a={}
for a.i = 1, 10 do
end

Workaround

a={}
for i = 1, 10 do
     a.i = i
end

I don’t see the point in not being able to directly use a table element as a counter in the for loop.

This doesn’t seem like a bug as it doesn’t look like supported syntax; I think it would be better to file an RFC for this. (RFC Guide)

1 Like

Hello rogeriodec_games,

This isn’t a bug, we don’t support this kind of syntax. I also cannot see us implementing something like this–this kind of side effect is non-obvious especially compared to the workaround code.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.