Conditionals are used to check something once, and then move on. Loop statements are used to continually run a piece of code until the condition is no longer true. Loop statements are often used with numerical values to see if a certain number of objects are present, or if a certain object has reached a designated spot on the stage. For instance, if we have an array of information, and we want to know each element in that array, we could use a loop statement to cycle through each element in an array until there are no more, like this: //create an array var myArray_array:Array = new Array("David","Ben","Lesley","Missy","Jen"); //now loop through the entire array and display each element in the output panel for(var i:Number = 0; i<myArray_array.length; i++){ trace(myArray_array[i]); } //Output: David // Ben // Lesley // Missy // Jen The preceding code creates an array full of names. Then a loop statement is created that will loop through the entire array and display each element in the Output panel. Loop statements can be very powerful, but also very processor-intensive, so make sure the loop does not continue forever. For more on loop statements, see Chapter 11. |