Friday, July 26, 2013

Dynamic Loop Condition

<script>
var favoriteAnimals = new Array("Brown Chicken", "Brown cow", "Green Tortoise", "White Rabbit", "Pink Panther");
favoriteAnimals.sort();

for (i = 0; i < favoriteAnimals.length; i ++) {
document.write(favoriteAnimals[i] + "<br>");
}

</script>

Now if the number of the items in the favoriteAnimals Array changes  so will the conditional of the forloop.


No comments:

Post a Comment