# If statement in AS - Going nuts!

**URL:** https://forum.kirupa.com/t/if-statement-in-as-going-nuts/136848
**Category:** Uncategorized
**Created:** [February 8, 2005, 10:47pm UTC](https://forum.kirupa.com/t/if-statement-in-as-going-nuts/136848 "2005-02-08T22:47:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![edacsac](https://avatars.discourse-cdn.com/v4/letter/e/0ea827/32.png) [@edacsac](https://forum.kirupa.com/u/edacsac)
#### Post date: [February 8, 2005, 10:47pm UTC](https://forum.kirupa.com/t/if-statement-in-as-going-nuts/136848/1 "2005-02-08T22:47:05Z")

</div>

Why does this not work in flash? It makes it through the first if statement where if done==1 and changes “done” to “2”, but once it moves left one increment it moves right again and continues to loop back and forth, and done remains “2”. Its like its ignoring “if done==2”.

```auto

box.onEnterFrame = function(){
	//set a variable to switch between right & left movement
	var done = "1";
	if(done == "1"){
		//Move right
		if(this._x < 530){
			this._x += 10;
		}
		//Threshold for right movement, set variable to move left
		if(this._x > 530){
			var done = "2";
		}
		trace(this._x);
		trace(done);
	}
	if(done == "2"){
		//Move left
		if(this._x > 24){
			this._x -= 10;
		}
		//Threshold for left movement
		if(this._x < 24.15){
			var done="3";
		}
		trace(this._x);
		trace(done);
	}
	if(done == "3"){
		// Do nothing, we're done.
		trace("Done!");
	}
}

```
