EG:break
var text =""
var i;
for(i =0; i <5; i++) {
if(i ===3) {
break;
}
text +="The number is "+ i +"";
}
Run...
The number is 0
The number is 1
The number is 2
EG: Label Break;
function myFunction() {
var text = ""; var i, j; Loop1: // The first for loop is labeled "Loop1"
for (i = 0; i < 3; i++) {
text += "" + "i = " + i + ", j = ";
Loop2: // The second for loop is labeled "Loop2"
for (j = 10; j < 15; j++) {
if (j === 12) {
break Loop2;
}
document.getElementById("demo").innerHTML = text += j + " ";
}
}
}
running...
EG: While
function myFunction() {
var text = "";
var i = 0;
while (i < 10) {
text += "The number is " + i;
i++;
}
document.getElementById("demo").innerHTML = text;
}
EG:do{}while()
function myFunction() {
var text = "" ;
var i = 0;
do {
text += "The number is " + i;
i++;
} while (i < 10)
document.getElementById("demo").innerHTML = text;
}
running...
do {
code block to be executed
}
while (condition);