# For Loop Code Help

**URL:** <https://forum.kirupa.com/t/for-loop-code-help/189131>\
**Category:** flash\
**Created:** [May 14, 2006, 3:35am UTC](https://forum.kirupa.com/t/for-loop-code-help/189131 "2006-05-14T03:35:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [May 14, 2006, 3:35am UTC](https://forum.kirupa.com/t/for-loop-code-help/189131/1 "2006-05-14T03:35:26Z")

</div>

This comes up often for me when coding. How do you target the previous MC in a for loop. Basically I am attaching MC’s to the stage that are 90 Pixels apart from the top and bottom. I want to check the \_x location of the previous MC and move in 90 pixels. Use an If statement so the \_x location is not beyond 260 and if it is it moves \_y 90 pixels and resets the \_x. Is this the best way to do it.

```auto
function yelGallery () {
 for (var i = 10; i < 20; i++) {
  var galleryMC:MovieClip = (_root.attachMovie ("galleryMC", "galleryMC" + i, i));
  galleryMC10._x = 70;
  trace (this.galleryMC) -1))
  if (this.galleryMC._x > 260) {
   this.galleryMC._x = 70;
   this.galleryMC._y = /*how do I target the previous MC*/this.galleryMC._y + 90;
  } else {
   this.galleryMC._x = this.galleryMC._x + 90;
  }
  _root.myMCL.loadClip ("Galleries/forSale/tn_forSale/tn_painting" + curPaintingNum + ".jpg", _root.galleryMC);
 }
}

```
