# For loops

**URL:** <https://forum.kirupa.com/t/for-loops/206890>\
**Category:** Uncategorized\
**Created:** [November 12, 2006, 10:18pm UTC](https://forum.kirupa.com/t/for-loops/206890 "2006-11-12T22:18:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![habes](https://avatars.discourse-cdn.com/v4/letter/h/e5b9ba/32.png) [@habes](https://forum.kirupa.com/u/habes)\
**Post date:** [November 12, 2006, 10:18pm UTC](https://forum.kirupa.com/t/for-loops/206890/1 "2006-11-12T22:18:36Z")

</div>

hey everyone, im working on a game and need to use a for loop for the enemies.  
the code works but it doesnt repeat, because its just on the main frame timeline.

```auto

for (e=1; e<=_root.enemyNum; e++) {
    var enemySet = _root.map["enemy"+e];
    enemySet.enemyHealth = 100;
    enemySet.onEnterFrame = function() {
        myRad = Math.atan2(_root.map.character._y-this._y, _root.map.character._x-this._x);
        myDeg = Math.round((myRad*180/Math.PI));
        this._rotation = myDeg+90;
        if (Math.abs(enemySet._x-_root.map.character._x)<=awareness && !this.hitTest(_root.map.character)) {
            if (_root.map.character._x<this._x) {
                this._x -= _root.enemySpeed;
            }
            if (_root.map.character._x>this._x) {
                this._x += _root.enemySpeed;
            }
        }
        if (Math.abs(enemySet._y-_root.map.character._y)<=awareness && !this.hitTest(_root.map.character)) {
            if (_root.map.character._y<this._y) {
                this._y -= _root.enemySpeed;
            }
            if (_root.map.character._y>this._y) {
                this._y += _root.enemySpeed;
            }
        }
        if (enemySet.enemyHealth<=0) {
            enemySet.gotoAndStop("dead");
        }
    };
}

```

do i need to use an enterFrame or is there another way to make it loop?  
thanks
