Lesson 10. Why does this work?


#1

var getToDaChoppa = function(){
var yes = false
do{
console.log("checking...");
console.log(yes)
}while (yes === true){
console.log("it's true! switching to false");
yes = false;
console.log(yes);
}

};

getToDaChoppa();

Why does the while loop run when yes isn't true? (I used === just to make sure)


#2

It ran only once. It will always run only once, regardless of condition state (true or false). It ran once, and your condition was false. It was expected.
I think that your messages in this code got you confused. You should do your code in do part of the loop, by doing it in while you're just confusing yourself. The code wont run if the condition is false, however if you can "trick" it to do something that is not usually done.


#3

Ah I see now. Thanks for the speedy reply @igorcaletacar