While (infinite) run infinitely



This code seems to be creating and infinite loop, though I do not understand why.

var i = true;

var soloLoop = function(){           //enter the loop
   while(true){                             //i is true so we continue
   console.log("Looped once!");   //should print on screen "Looped once!"
   i = false;                                //i is now false.  This should stop the loop.

soloLoop();                                //This calls the function which should result 
                                                //in "Looped once!"

results in an infinite loop and the browser giving up waiting to regain control


You didn't say while what was true. One way to say while value is true would be to just say the value, for instance:


That is one way to say while i is true then print this code.

Hope this helped :slight_smile:


The problem is occurring in your while loop's conditional statement. Instead of looking for true you should be looking for while i is true. Use while(i) and you should be good.


Ah. yes, that resolves it. Thank you, both. I appreciate the help.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.