Monday 16 July 2012

How to create While loop using javascript


<!DOCTYPE html>
<html>
<body>

<p>Click the button to loop through a block of as long as <em>i</em> is less than 5.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script type="text/javascript">
function myFunction()
{
var x="",i=0;
while (i<5)
  {
  x=x + "The number is " + i + "<br />";
  i++;
  }
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

0 Responses to “How to create While loop using javascript”

Post a Comment