A while statement can be used even when the number of times is unknown. : while « Statement « Flash / Flex / ActionScript






A while statement can be used even when the number of times is unknown.

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var nIndex:Number = 0;
        var aValues:Array = [1,2,3];
        
        while(aValues[nIndex] != null && nIndex < aValues.length) {
          trace(aValues[nIndex]);
          nIndex++;
        } 
        for(var i:Number = 0; i < aValues.length; i++) {
          if(aValues[i] == null) {
            break;
          }
          trace(aValues[i]);
        }
        

    }
  }
}
1
2
3
1
2
3

        








Related examples in the same category

1.while Statement
2.Use while loop to calculate 2 to the power of 3
3.Use the increment operator with while loop
4.Processing Lists with while Loops
5.Ending a while Loop with the break Statement
6.Use while loop to sum 100 ramdom numbers