Infinite loops in While loops review


#1



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


Hi everyone!

Can anyone explain me why the following code turns into infinite loop? In my opinion it's exactly the same as the code in the previous exercises which worked just fine, but surely I just don't see something wrong in the code.

Could You tell me what is wrong with it?

Thanks in advance.


var understand = true;

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


Everything works fine when I change while (understand) to while (understand === false)...
Which makes me totally confused...


#2

@arsengael
you are mashing the do-while-loop and while-loop...

the while-loop:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while

the do-while-loop:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while


#3

Thanks man! Definitely didn't see it won't work that way...