# For loop troubles

**URL:** https://forum.kirupa.com/t/for-loop-troubles/308685
**Category:** Uncategorized
**Created:** [April 28, 2010, 7:52am UTC](https://forum.kirupa.com/t/for-loop-troubles/308685 "2010-04-28T07:52:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![RebeccaLessay](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@RebeccaLessay](https://forum.kirupa.com/u/RebeccaLessay)
#### Post date: [April 28, 2010, 7:52am UTC](https://forum.kirupa.com/t/for-loop-troubles/308685/1 "2010-04-28T07:52:27Z")

</div>

Hi me again 😛  
Got the script working now but not as I want it to.  
The trouble lies in the for-loop. What I want it to do is: perform 1 if and then end the loop and sent the new data to erhm…something that remembers it 😛

So the next time you click a block the loop starts with the new data etc etc.

```auto
var blockList = new Array();

for(var i:int = 0; i < 25; i++)
{
	var xAs:int = i % 5;
	var yAs:int = i / 5;
	
	var block:MovieClip;
	
	if(xAs == 0 || yAs == 0 || xAs == 4 || yAs == 4)
	{
		block = new mcWall();
	}
	else if(xAs != 1 || yAs != 1)
	{
		block = new mcBlock();
		block.addEventListener(MouseEvent.CLICK, movement);
	}
	else if(xAs == 1 && yAs == 1)
	{
		block = new mcEmpty();
	}
	
	block.x = xAs * 100;
	block.y = yAs * 100;	
	
	addChild(block);

	blockList* = block;
}

function movement(event:MouseEvent)
{
	trace(event.target);
	
	var clickedIndex:int = 0;

	// zoek de juiste index waarde 
	for(var i:int = 0; i < blockList.length; i++)
	{
		if(blockList* == event.target)
		{
			clickedIndex = i;
		}
	}
	
	// zoek de juiste index waarde van mcEmpty
	for(var empty:int = 0; empty < blockList.length; empty++)
	{
		if(blockList[empty] == mcEmpty)
		{
			clickedIndex = empty;
		}
	}
	
	// controleer om clickedIndex heen
	
	
		if(blockList[clickedIndex -1] is mcEmpty)
		{
			event.currentTarget.x -= 100;
			
			blockList.splice(clickedIndex -1);
			blockList.splice(empty +1);
		}
		
		else if(blockList[clickedIndex +1] is mcEmpty)
		{
			event.currentTarget.x += 100;
			
			//blockList.splice(clickedIndex +1);
	// blockList.splice(empty -1)
		}
		
		else if(blockList[clickedIndex -5] is mcEmpty)
		{
			event.currentTarget.y -= 100;
			
			//blockList.splice(clickedIndex -5);
	// blockList.splice(empty +5)
		}
		
		else if(blockList[clickedIndex +5] is mcEmpty)
		{
			event.currentTarget.y += 100;
			
			//blockList.splice(clickedIndex +5);
	// blockList.splice(empty -5)
		}
		
		else if(blockList[clickedIndex +5]!= mcEmpty)
		{
			trace ("not possible");
		}
			
		else if(blockList[clickedIndex -5]!= mcEmpty)
		{
			trace ("not possible");
		}
			
		else if(blockList[clickedIndex +1]!= mcEmpty)
		{
			trace ("not possible");
		}
			
		else(blockList[clickedIndex -1]!= mcEmpty)
		{
			trace ("not possible");
		}
		trace(clickedIndex);
}

```
