Atrag
Atrag

Reputation: 743

unexpected symbol near '<='

It would be so wonderful if it would tell me what the unexpected symbol is but alas it doesn't. Can someone please advice me what is wrong with this:

for i = 1, 100 do
if i <= 3 then
local rowMenu = 1
elseif <= 6 then
local rowMenu = 2
elseif <= 9 then
local rowMenu = 3
elseif <= 12 then
local rowMenu = 4
elseif <= 15 then
local rowMenu = 5
elseif <= 18 then
local rowMenu = 6
elseif <= 21 then
local rowMenu = 7
elseif <= 24 then
local rowMenu = 8
end
end

I plan on calculated the placement of objects within the loop - its not complete - but I don't understand why this shouldnt work.

Thank you.

Upvotes: 2

Views: 710

Answers (1)

lhf
lhf

Reputation: 72312

The complier is telling you that after seeing elseif it expected something that starts an expression but it found <=, which doesn't.

You need to mention i explicitly in all tests:

elseif i <= 6 then

Note that these chains of ifs can be replaced by

rowMenu = 3*math.ceil(i/3)

or

rowMenu = 3*((i//3)+(i*i)%3)

Upvotes: 5

Related Questions