For loop, update variabel ewery time it hits 3

Hi guys

I wanna do a gallery that loads 3 thumbnails next to each other and ewery 3th time I wanna update _y and _x positions of the duplicated clip.

Example

So the first 3 times I wanna update a variabel for _x, after the 3th time reset it and update a variabel for _y.

I could do this with some if statements but I dont know how many images there will be.

Anybody got any ideas:look:

Edit: I thought that putting counter variabels outside the loop and put one if should do it.
if(counter==3){
counter=0;
}