Javascript - Write program to Use the break statement to stop the loop.

Requirements

Use the break statement to stop the loop at 5.

Insert an if statement that checks if i is equal to 5, then stop the loop with break;


var text = "";
var i;
for (i = 1; i < 10; i++) {
    //your code here
    console.log( i );
}

Demo

var text = "";
var i;//from  ww w  .  java2 s .co  m
for (i = 1; i < 10; i++) {
    if (i === 5) break;
    console.log(  i + "\n" );
}

Result

Related Exercise