Use while loop to output all elements in an array : while « Statement « JavaScript Tutorial






<html>
<head>
<title>Use while loop to output all elements in an array</title>
</head>
<body>

<h1>Use while loop to output all elements in an array</h1>

<script language="javascript" type="text/javascript">
<!--

var ages = new Array(12,57,32,6,21,19);
var i=0;
while (ages.length) {
  var tempAge = ages.pop();
  document.write("<P>" + tempAge + "</p>");
}
//-->
</script>

</body>
</html>








3.6.while
3.6.1.while loop
3.6.2.Use integer variable to control the while loop
3.6.3.Check the loop counter for while loop
3.6.4.Use while loop to output all elements in an array
3.6.5.Use Do while loop to reverse a string
3.6.6.Nesting If statement to a while statement
3.6.7.Using While loop to check user input