April 21, 2009

0 JavaScript while loop

The while loop

The while loop is used when you want the loop to execute and continue executing while the specified condition is true

while (var<=endvalue)
{
code to be executed
}

Note :The <= could be any comparing statement.

Tutorial

The tutorial below defines a loop that starts with i=0. The loop will continue to run as long as i is less than, or equal to 10. i will increase by 1 each time the loop runs.

<html>
<head>
<script type="text/javascript">
var i=0
do
{
document.write ("The number is "+ i )
document.write ("<br />")
i=i + 1
}
while ( i < 0 )
}
</script>
</body>
</html>









0 comments:

Post a Comment

Blogger Themes

 
Powered by Blogger