Skip a 'for' Loop iteration.

Hello Everyone.

I’m trying to optimise my ‘for’ loop.
I have a tile system, this ‘for’ loop is to populate the tile with the relevant tiles according an array.

I want to be able to skip an iteration of the ‘for’ loop.

Let’s take a look:

for i = 0, 0 do  
 for j = 0, 0 do  
 local quad = display.newGroup()  
 quad.x = i \* 30  
 quad.y = j \* 30  
 map:insert(quad)  
  
 --tiles in quadrant  
 for i = 0, 71 do -- x length of Array -1 due to 00.  
 for j = 0, 8 do -- y length of Array -1 due to 00.  
 local tile = sprite.newSprite(tileSet)  
 tile.currentFrame = map.sceneryTiles[1][(1+j)][(1+i)]+1 --random(36)  
  
 --if tile.currentFrame == 0+1 then  
 --tile:removeSelf() --Want to skip over this if it's 00 and go to the next tile.  
 --end  
  
 if tile.currentFrame \> 3-2 and tile.currentFrame \< 3+2 then  
 physics.addBody(tile,"static", {bounce = 0.0, shape = { -20,-20, 20,-20, 20,-20, -20,-20 }})--  
 tile.Collision = "floor"  
 --print("Grass:", tile.currentFrame)  
 end  
  
 if tile.currentFrame \> 13-2 and tile.currentFrame \< 92+2 then  
 physics.addBody(tile,"static", {isSensor = true})  
 tile.Collision = "trash"  
 end  
  
 if tile.currentFrame == 94+1 then  
 physics.addBody(tile,{bounce = 0.5, radius = 13})  
 tile.Collision = "coin"  
 --print("Bush:", tile.currentFrame)  
 end  
  
 tile.x = i \* 40  
 tile.y = j \* 40  
 quad:insert(tile)  
 end  
 end  
 end  
end  

Basically it loops through once and on certain tiles I can add certain physics bodies, the 2 I’ve added so far are walkable sections for the ‘floor’ and circular collectable for ‘coins’.

I’m having trouble skipping over 00 tiles.
Basically on tiles with 00 I have designated a blank tile in my tilemap. The sky is full of these ‘blank’ tiles.
But the fact is they’re still actually there, which I imagine is wasting time and performance.

If I check if it’s a 00 and then just skip over that tile to the next, that’d be great.
Is there anyway I can skip over the ‘for’ sequence once if it see’s a 00 tile?
(I’ve already got it set up to check if it’s a 00 tile)

[import]uid: 91798 topic_id: 29805 reply_id: 329805[/import]

use an if statement inside the inner loop before you do any of the creation. Don’t create the sprite, and don’t add it to physics.

for example:

for i=...  
 for j= ...  
 local frame = map.sceneryTiles[1][(1+j)][(1+i)]+1   
 if frame ~= 00 then  
 -- create the tile  
 end  
 end  
end  

[import]uid: 122310 topic_id: 29805 reply_id: 119523[/import]

Yeah that worked a treat, I was going for the opposite way where I check if it WAS 00.

But that WAS NOT worked great. Thanks =) [import]uid: 91798 topic_id: 29805 reply_id: 119525[/import]

use an if statement inside the inner loop before you do any of the creation. Don’t create the sprite, and don’t add it to physics.

for example:

for i=...  
 for j= ...  
 local frame = map.sceneryTiles[1][(1+j)][(1+i)]+1   
 if frame ~= 00 then  
 -- create the tile  
 end  
 end  
end  

[import]uid: 122310 topic_id: 29805 reply_id: 119523[/import]

Yeah that worked a treat, I was going for the opposite way where I check if it WAS 00.

But that WAS NOT worked great. Thanks =) [import]uid: 91798 topic_id: 29805 reply_id: 119525[/import]