Loops through the statements enclosed within theĀ { code block } until the test_expression is false:
while (test_expression) {
statements ;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<html> <head> <title>JavaScript</title> </head> <body> <script type="text/javascript"> var val = 0; while (val < 5) { document.write("val = " + val + "<br>"); val++ ; //increment val } </script> </body> </html> |
Save & refresh browser:
val = 0 val = 1 val = 2 val = 3 val = 4 |