Help on for loops

Hi everyone…

I have this for loop, and it works great

local clefTable = {} local index = 0     for row = 1, 4 do         for column = 1, 6 do         local clefKey = display.newImageRect("images/trebleClef.png", 71, 182)         clefKey.x = (row \* 120) -12         clefKey.y = column \* 100         clefTable[index] = clefKey         clefTable[index].index = index         end     end

But i just want to make the four images for the rows, no columns, i put 0, and 0 like this:

local clefTable = {} local index = 0     for row = 1, 4 do         for column = 0, 0 do         local clefKey = display.newImageRect("images/trebleClef.png", 71, 182)         clefKey.x = (row \* 120) -12         clefKey.y = column \* 100         clefTable[index] = clefKey         clefTable[index].index = index         end     end

It’s that the right way, or correct way?

or this there another way of doing images just in rows?

Thanks

Victor

If you do no want columns then you can just remove the column loop completely, and place the rest of the code within the row loop.  You will need to adjust your Y coordinate accordingly.

Thank you, I got the idea. I just had to removed 3 lines and change the Y value, like this

local whiteKeysTable = {}     local index = 0         for row = 1, 10 do             --for column = 1, 2 do             index = index + 1         local whiteKey = display.newImageRect("images/whiteKey.png", 110, 361)             whiteKey.x = (row \* 100) - 37             whiteKey.y = 564             --whiteKey.y = column \* 104             whiteKeysTable[index] = whiteKey             group:insert ( whiteKeysTable[index] )             --end         end

Thanks

Victor

If you do no want columns then you can just remove the column loop completely, and place the rest of the code within the row loop.  You will need to adjust your Y coordinate accordingly.

Thank you, I got the idea. I just had to removed 3 lines and change the Y value, like this

local whiteKeysTable = {}     local index = 0         for row = 1, 10 do             --for column = 1, 2 do             index = index + 1         local whiteKey = display.newImageRect("images/whiteKey.png", 110, 361)             whiteKey.x = (row \* 100) - 37             whiteKey.y = 564             --whiteKey.y = column \* 104             whiteKeysTable[index] = whiteKey             group:insert ( whiteKeysTable[index] )             --end         end

Thanks

Victor