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>
This post was written by: Bharathi
Bharthi is a professional blogger, web designer and front end web developer. Follow him on Twitter
Subscribe to:
Post Comments (Atom)
0 Responses to “How to create While loop using javascript”
Post a Comment