Loop statements are used to reduce the number of lines of codes.
The while loop
The JavaScript while loop is used to execute codes iteratively/repeatedly until the condition or expression becomes false. when the condition becomes false it terminates or stops the execution of codes.
syntax
while (expression) { Statements //to be executed if the expression is satisfied or teue. }
Example
<html> <head> <title>JS while loop</title> </head> <body> <script> var n=1; document.write("--Start--"+"</br>"); while (n<=10) { document.write(n+"</br>"); n++; } document.write("--End--"); </script> </body> </html>
0 Comments