5.5.5 while..do statement
The while loop is used when you want the loop to execute and continue executing while the specified condition is true. It tests the condition at the beginning of the loop, itself if the condition is true it executes the statements within the body of the loop or else it terminates.
<html> <body> <script type =”text/javascript”> <!.. Var myCounter = 0; Var linebreak = “<br/>’; document.write(“while loop is beginning”); document.write(linebreak); while (myCounter < 10) { document.write (“myCounter =”+ myCounter); document.write(linebreak); myCounter++; } Document.write (“while loop is finished!”); </script> </body> </html>
Related Posts:
Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)
Subscribe Here (or)
Since the body of the loop does not modify number, then it will always be -1 when evaluating the condition, and thus the condition will always evaluate to true. The loop never stops executing.
The loop will be stop after myCounter variable reach value 10.