# Converting some AS2 while loop to AS3

**URL:** <https://forum.kirupa.com/t/converting-some-as2-while-loop-to-as3/319316>\
**Category:** flash\
**Created:** [February 16, 2011, 4:45am UTC](https://forum.kirupa.com/t/converting-some-as2-while-loop-to-as3/319316 "2011-02-16T04:45:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eddie\_E](https://avatars.discourse-cdn.com/v4/letter/e/2acd7d/32.png) [@Eddie\_E](https://forum.kirupa.com/u/Eddie_E)\
**Post date:** [February 16, 2011, 4:45am UTC](https://forum.kirupa.com/t/converting-some-as2-while-loop-to-as3/319316/1 "2011-02-16T04:45:23Z")

</div>

Hi

I have a while loop I use that shuffles my array in AS2, I have to convert all my code to AS3 which seems to have an issue with the following:

```auto
var randomArray = shuffle(orderArray);
function shuffle(toShuffle) { // shuffles an array
	var newMcOrder = new Array();
	while (!end) {
		myRandom = random(toShuffle.length);
		selected = toShuffle[myRandom];
		toShuffle.splice(myRandom, 1);
		newMcOrder.push(selected);
		if (toShuffle.length == 0) end = true;
	}
	return newMcOrder;
}

```

Any idea what I need to do to get this working with AS3?

thanks

Ben
