Is this creating an Infinite loop, the tab crashes whenever I submit


#1


https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/0/2?curriculum_id=506324b3a7dffd00020bf661

Tab open in the browser freezes


var understand = true;

while(understand = true){
	console.log("I'm learning while loops!");
	understand = false
}


#2

Yes it is, Loops always have to be incremented! If your variable = true outside the loop it must change to false for the loop to end


#3

The problem is this condition. Mainly this part:

understand = true

this is not a comparison but an assignment. So first of all understand = true will make understand become true no matter what it initially was. But even worse the expression understand = true itself has a value of true (because assignments itself always have the value you assign) therefore you have while(true) which is an infinite loop.

To fix it just use == or === instead of =.


I dont understand
#4

The proper way to run your code would be

var understand = true;

while(understand) {
	console.log("I'm learning while loops!");
	understand = false;
}

When you write with the = true and without a semicolon after understand = false Its as if you want your loop never to end.