Need help with While loop, please


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;


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



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


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


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