Hi,

I have strange problem with a standard for loop..

It should go from -2, to 2 (-2, -1, 0, 1, 2) but when I debug the program and place the red dot inside the loop and look at the "i" value it goes from -2 directly to 2 after first loop. (-2, 2) which is puzzling me why?

here is the loop:

for(int i = -2; i < 3; i++) { if(myMap[(y-2) * myMapW + x+i].properties != 0 && myMap[(y-1) * myMapW + x+i].properties != 1) { tileTemp.sprite = 1;//if(getTileSprite(x+i, y-2) > 2) tileTemp.sprite = rand()%2 + 1; tileTemp.entity = this->getTileEntity(x+i, y-2); tileTemp.properties = 2; myMap[(y-2) * myMapW + x+i] = tileTemp; } }

I tried to change the negative numbers so the loop should go from 0, 1, 2, 3 and 4 but it goes from 0 to 4 right after first loop... why?

for(int i = 0; i < 5; i++) { if(myMap[(y-2) * myMapW + x+i-2].properties != 0 && myMap[(y-1) * myMapW + x+i-2].properties != 1) { tileTemp.sprite = 1;//if(getTileSprite(x+i-2, y-2) > 2) tileTemp.sprite = rand()%2 + 1; tileTemp.entity = this->getTileEntity(x+i-2, y-2); tileTemp.properties = 2; myMap[(y-2) * myMapW + x+i-2] = tileTemp; } }

I use visual studio 2010 and for loop so far have worked as it should.. well, until now

**Edited by Killerko, 14 June 2014 - 06:05 PM.**