Lesson 2. While Syntax (Please help!)

Every time i run this code, my browser crashes, like it does with an infinite loop. I’m not entirely certain what is happening, and every time I try something different, it crashes. Please help if you can!

You have an infinite loop. Post your code, or we can’t help you.

Sorry. Slipped my mind. I copied it but never pasted it.

var understand = true;

while( “I’m learning while loops!” ){
console.log();
understand = false;
}

I think you are confused, here is while syntax:

while (condition) {
//Statements
//Change Condition
};

You have a string as a condition, which will always be true.

var understand = true;

while( ){
console.log(“I’m learning while loops!”);
understand = false;
}
Syntax error: Unexpected token )

Not entirely certain where I made the mistake.

You left out the condition in your loop.

Thanks. Guess this is what happens when you stay on Codecademy for more than 12 hours.

12 hours? Amateur! (jk) :slightly_smiling:

In my defense I’m doing this on 4 hours of sleep. :stuck_out_tongue:

Fair enough! :slightly_smiling:

The code is:

var understand = true;

while (understand === true) {
console.log(“I’m learning while loops!”);
understand = false;
}

3 Likes

It isn’t necessary to put understand === true, just put understand.