Help with for loop code.

I have two tables, the for loop I use to output the table content is supposed to loop 25 times but I cant get it to work, I keep getting an unexpected symbol error and I am not sure why. I even made it to where now I am just trying to output a single string 25 times to see if I could get that to work but no luck. 

Here is my code, any help is appreciated.

CODE

local tips = { "W", "R", "Blk", "Y", "V" }; local rings = { "Bl", "Or", "G", "Br", "S" } local fontSize 22; -- Display 25 pair logic for i = 1, 25 do local indxT = 1; -- index for tip local indxR = 1; -- index for ring local ifRun = 1; -- number of times the for loop has ran. -- change tip color if var equals number if (ifRun == 5 or ifRun == 10 or ifRun == 15 or ifRun == 20) then -- increment tip indxT = indxT + 1; end -- End if statement local highPair = display.newText( "hello", 20,20,native.systemFont,fontSize); indxR = indxR + 1; -- Increment Ring color -- reset rings after using last ring color if indxR == 5 then indxR = 1; end end -- Ends for loop

On line 3 above you forgot the ‘=’ sign

local fontSize = 22;

Another problem with the code – line 16, when you create the newText objects, you put them all on top of each other.  The “20,20” options are top,left coordinates.

JonPM’s suggestion is also needed … I’m surprised it’s not throwing some kind of syntax error there.

Thank you for pointing that out, I did forget to add the ‘=’ symbol. I also noticed the output was being displayed one over the other. 

I fixed those two issue but now I think my logic might be wrong.

The loop is supposed to show like this.

W B

W O

W G

W Br

W S

R B

R O

R G

R Br

R S 

And it is supposed to keep going displaying all the colors in my tables in a certain order. Every time the loop completes 5 cycles the indxR is supposed to reset back to 1 starting with the first item in my table again. the indxT is incremented every time the ifRun is equal to 5, 10, 15, or 20, ifRun keeps count of the amount of times the loop has ran.

The result I get with my current logic is

W Bl

W O

W G

W Br

R Bl

R O

R Gr

R Br

R Bl

so rather than showing 5 cycles of W it only shows 4 and rather than having S be the last color it shows Br as the last color. When it comes to R it does cycle 5 times but again it does not show S it from from Bl to Br then shows Bl again instead of S.

Not sure why.

Here is the code.

-- Variables local tips = { "W", "R", "Blk", "Y", "V" }; local rings = { "Bl", "Or", "G", "Br", "S" } local fontSize = 16; -- 25 pr loop vars local indxT = 1; -- index for tip local indxR = 1; -- index for ring local ifRun = 1; -- number of times the for loop has ran. -- Display 25 pair logic for i = 1, 25 do -- change tip color if var equals number if (ifRun == 5 or ifRun == 10 or ifRun == 15 or ifRun == 20) then -- increment tip indxT = indxT + 1; end -- End if statement local highPair = display.newText( tips[indxT] .. " " .. rings[indxR], 20,i\*20,native.systemFont,fontSize); print( tips[indxT] .. " " .. rings[indxR]); indxR = indxR + 1; -- Increment Ring color ifRun = ifRun + 1; -- reset rings after using last ring color if indxR ==5 then indxR = 1; end end -- Ends for loop 

On line 3 above you forgot the ‘=’ sign

local fontSize = 22;

Another problem with the code – line 16, when you create the newText objects, you put them all on top of each other.  The “20,20” options are top,left coordinates.

JonPM’s suggestion is also needed … I’m surprised it’s not throwing some kind of syntax error there.

Thank you for pointing that out, I did forget to add the ‘=’ symbol. I also noticed the output was being displayed one over the other. 

I fixed those two issue but now I think my logic might be wrong.

The loop is supposed to show like this.

W B

W O

W G

W Br

W S

R B

R O

R G

R Br

R S 

And it is supposed to keep going displaying all the colors in my tables in a certain order. Every time the loop completes 5 cycles the indxR is supposed to reset back to 1 starting with the first item in my table again. the indxT is incremented every time the ifRun is equal to 5, 10, 15, or 20, ifRun keeps count of the amount of times the loop has ran.

The result I get with my current logic is

W Bl

W O

W G

W Br

R Bl

R O

R Gr

R Br

R Bl

so rather than showing 5 cycles of W it only shows 4 and rather than having S be the last color it shows Br as the last color. When it comes to R it does cycle 5 times but again it does not show S it from from Bl to Br then shows Bl again instead of S.

Not sure why.

Here is the code.

-- Variables local tips = { "W", "R", "Blk", "Y", "V" }; local rings = { "Bl", "Or", "G", "Br", "S" } local fontSize = 16; -- 25 pr loop vars local indxT = 1; -- index for tip local indxR = 1; -- index for ring local ifRun = 1; -- number of times the for loop has ran. -- Display 25 pair logic for i = 1, 25 do -- change tip color if var equals number if (ifRun == 5 or ifRun == 10 or ifRun == 15 or ifRun == 20) then -- increment tip indxT = indxT + 1; end -- End if statement local highPair = display.newText( tips[indxT] .. " " .. rings[indxR], 20,i\*20,native.systemFont,fontSize); print( tips[indxT] .. " " .. rings[indxR]); indxR = indxR + 1; -- Increment Ring color ifRun = ifRun + 1; -- reset rings after using last ring color if indxR ==5 then indxR = 1; end end -- Ends for loop