The while loop can be summarized as while the expression evaluates to true, execute the statements in the loop.
Once the last statement in the loop is executed, go back to the top of the loop and evaluate the expression again.
When the expression evaluates to false, the next line of code following the while loop structure is executed.
Because the expression is evaluated before the loop, it is possible the loop will never be executed.
The format of the while loop looks like the following:
while (expression) { statement; } |
Example 1
<html> <head> </head> <body> <SCRIPT LANGUAGE='JavaScript'> <!-- var counter = 1; document.write("While loop is Starting<br>"); while (counter <= 5) { document.write("Counter Now",counter,"<BR>"); counter++; //Next car } document.write("While loop is finished!"); //--> </SCRIPT> </body> </html>
0 comments:
Post a Comment