Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Lesson 5 Level 5

We have a simple while loop in the editor, which is printing values 0 to 9. We want you to use the break statement, to break out of the loop after printing 5 in the console.

You will have to use if condition for this, we hope you remember how to use it. Please increment the value of x after the if condition, which means add the if condition between console.log() statement and the x++; statement, inside the while loop.


what will the correct code of this exercise? Can someone help me...??
by

2 Answers

springBootGuru
let x = 0;

while (x < 9) {
if (x === 5) {
break;
}
x = x + 1;
}

console.log(x);

// expected output: 5
cqod29v
let x = 0;

while(x < 10)
{

console.log(x);

if(x===5){

break;
}
x+=x;


}
console.log();

Login / Signup to Answer the Question.