Need help with While loop, please


#1


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


What am I supposed to do here? When I put in while (understand = true), the browser freezes from what I think might be from an infinite loop? But shouldn't the understand = false; statement below overrides the former value of understand? Please, help.

Thank you.


var understand = true;

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


#2

So, your while condition which remains true at all point isn't defined. Fill it in the braces.


#3

Try:

var understand = true
while (understand) {
console.log("I'm learning while loops!");
understand = false;
}

This works because the variable understand evaluates to true or is a true statement (Ex. 1+1=2; true)
In order for your while tag to print in your statement it has to be considered true. If left "true" then your statement would be infinitely printed, and your computer may crash. So you then make the while statement false to stop printing your statement(Ex. 1+1=3, false)
The variable just simplifies having to write that out in a longer string of code.

Im not a professional but that's my understanding hope I helped


#4

Thank you.
Javascript is hard in the beginning :slight_smile:


#6

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