Why is this infinite?


#1


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


it's an infinite loop. I'm not sure why. what should my condition be?


var understand = true;

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


#2

We cannot write an assignment in a conditional expression. Remove = true.

while (understand) {

#3

The "=" in JavaScript is the assignment operator, not a comparison operator.
The comparison operator is "===".
So you should write either this:

 while (understand === true)

or this:

 while(understand)

#4

This is redundant, and a habit to steer away from, imho.


#5

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