Why is that an infinite loop?


#1

//Remember to make your condition true outside the loop!

var soloLoop = function(){
//Your code goes here!
var i = true;
while(i === true);{
console.log("Looped once!");
i = false;
}
};

soloLoop();


#2

Because, probably there's a semilicon after while loop condition and it probably terminates the process of executing other lines of code. while(i === true) { you don't need semilicon here.


#3

Ah....yeah it was that ; which caused the problem. Thanks alot.


#4

even worse :slightly_smiling:
If you have a look at this:


The ; here doesn't terminate the loop it somehow does the job of the part in {}. So this:

var i = true;
while(i === true);

would be an infinite loop.


#5

You're right, as long as I can remember I've never faced with this problem, because it even didn't happen to me accidentally. :smiley: