While syntax


#1

var understand = true;

while(understand!=false){
console.log("I'm learning while loops!");
understand = false;
}
Why doesn't this work?? help.thx


#2

while(understand) {

#4

thank you so much it worked!


#5

what neither answers explain is that if you do:

while(understand)

there is no need to check condition, understand is true, so the loop gets executed. Then understand becomes false, and the loops exits. You surely remember a if statement, usually you use them to check something:

if (3 < 5){ /* do something */ }

but you can also just do:

if (true){ /* do something */ }

same for loops