Unexpected Infinite Loop


#1


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



For some reason, this code turns into an infinite loop.

var understand = 1;

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


#2

On your while statement, you used = instead of ==

Remember:
= (assignment operator) is used to assign a value to a variable, element of an array, or property of an object
== (equality operator) is used to compare two values or expressions


#3

Thank You!!! I don't know what else to say, but thanks!


#4

Additionally, it's best to use 3 equal signs, ===, since:
== : equal to
=== : equal value and equal type


#5

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