9 the do/while loop


9 the do/while loop

this stuff is confusing me

the do/while loop does something first and then check if its true. if its true, it continues, if its false it stops that means it only run once right?


var loopCondition = false;

do {
console.log("I'm gonna stop looping 'cause my condition is " + loopCondition + "!");
} while (loopCondition);

so now, i dont get it.
a variable was created called false. it can be called anything right?
now the computer was asked to print I'm gonna stop looping cause blah blah blah while loop condition is false. but loop condition was already set to false and this condition is going to be true forever because loopcondition is false. there is no way to make it stop.

can someone kindly explain.

 while (loopCondition)

is not looking for false, but true which loopCondition is not. That's why the loop ends.


OK i get how you write a true.... but what if i wanted to write a false like create an infinite loop...i wont do that but i just want to know how to it.


We would never actually compare to true or false, but what we can do is,

var f = false;
do {

} while (f);

to end the loop, or,

do {

} while ( ! f );

to create an infinite loop.


OK cool thanks xo much......


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