Latest Movie :
Home » » While Loop Statement

While Loop Statement

{[['']]}

The JavaScript while loop is much simpler than the for loop. It consists of a condition and the statement block.

Syntax:

while (condition)
{
...statements...

}

Ex1:

<script>

var msg = "";
var x = 1;
while (x <= 10)
{
msg = msg + x + "\n";
x++;

}

alert(msg);</script>

Ex2:

<script>

var msg = "";
var x = 1;
var res = 0;
while (x <= 10)

{

res = 12 * x;
msg = msg + "12 X " + x + " = " + res + "\n";
x++;

}
alert(msg)


</script>

Output: n/a

Share this article :
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. isophal.com - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger