Infinite Loop error



I keep getting an infinite loop error, though I can't figure out where I am going wrong. Anyone able to point it out? Thank you very much.

var status = true

for (var i = 0; i < 5; i++) {
while(status) {
console.log("this text once");
status = false;


I figured out that it was the while (status) at issue. I have corrected it with the below

var status = true

for (var i = 5; i > 0; i--) {
while(status === true) {
console.log("this text once");
status = false;

However, now it won't print the "this text once" line. :frowning:


This is interesting.
I don't think your change should make any difference (testing if a boolean is equal to true produces the same boolean), but then again I also don't think that's an infinite loop.

But I get an infinite loop as well.


I don't why but your first code works if you chance the var status with another word


Yeah, I just tried changing it out as well.

status is probably a built-in variable that can't be changed.

10/10 best language

But the thing is, when I print out status, it DOES say false as if it were changed. So..why then doesn't the loop stop, when the variable does appear to be changed?

Maybe it's converted to string? And non-empty strings are truthy

var status = true;
console.log(typeof false);
console.log(typeof status);


Again, JavaScript is clearly the best language there is.