advanced
   

SocialTwist Tell-a-Friend

Introduction Syntax Placement Variables Operators Popup Boxes If Else Statement Switch Case while Loop for Loop break continue Function Array DOM Events Date String Form Validation

JavaScript : while Loop

while Loop is the most common loop used in Javascript, when you need to perform some action over and over again.

while Loop
while Loop is used to execute the peice of code repeatedly. it looks like the following:

while (expression){
Statement(s) to be executed if expression is true
}

Till the 'expression' in parentheses evaluates to true, the statement is executed; otherwise, the statement is skipped. If two or more lines of code are to be executed, curly braces {} must be used to designate what code belongs in the while Loop.
For example,

<html>
<head>
<script type="text/javascript">
<!--
function whileLoop() {
var a=0;
document.write("Starting while Loop" + "<br />");
while (a < 10){
document.write("Current Count : " + a + "<br />");
a++;
}
document.write("while Loop stopped!");

}
//-->
</script>
</head>
<body onload="whileLoop()">

</body>
</html>


Previous            Next
Contact Us
Your Ad Here