Varun Varun - 1 year ago 81
HTML Question

JavaScript While Loop Error

While Loops
var a = 1;
while(a < 10) {
document.write("Hello World<br />")

Here is my while loop code when I run my code in Firefox browser or other browser like Chrome in Firefox it crashes and in Chrome it only loading occurs Right now I am following tutorial of bucky roberts from site:
I have Entered the Same code which he has written in his video but then to its not working ...please some one help to find problems regarding While Loop please .. Thanks In Advance.... I have set my Variable value as
a = 1
And setting it as
and I am Incrementing it as
but it is looping infinite times ..

xlm xlm
Answer Source

Your loop never terminates because a++ is outside of your while loop. Hence it never terminates as expected. If you look at his code again, the post incrementing of a is in the loop:

var a = 1;
   document.write("Hello World<br />")

Compare this with his code and yours and you'll see the difference.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download