break, continue and label statements break, continue and label statements

break, continue and label statements

 

break statement will immediately exit the loop, 2904628156

Copy the code
var n = 0;
for (var i=1; i < 10; i++) {
if (i % 5 == 0) {
break;
}
a ++;
}
alert(num); //4
Copy the code

Forced to continue following the loop statement. And although also continue statement exits the loop immediately, but will exit the loop from the top of the cycle

Ministry to continue.

Copy the code
var n = 0;
for (var i=1; i < 10; i++) {
if (i % 5 == 0) {
continue;
}
a ++;
}
alert(num); //8
Copy the code

 

 

Copy the code
var n = 0;
outermost:
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
if (i == 5 && j == 5) {
break outermost;
}
a ++;
}
}
alert(num); //55
Copy the code

Adding this tag will result will not only lead to a break statement to exit within the
Ministry for the statement (that is, using a variable j loop), but also withdraw from the outside for the statement (that is, using a loop variable i).

 

Copy the code
var n = 0;
outermost:
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
if (i == 5 && j == 5) {
continue outermost;
}
a ++;
}
}
alert(num); //95
Copy the code

 continue statement forces continue the cycle - to exit the inner loop, the outer loop.

break statement will immediately exit the loop, 2904628156

Copy the code
var n = 0;
for (var i=1; i < 10; i++) {
if (i % 5 == 0) {
break;
}
a ++;
}
alert(num); //4
Copy the code

Forced to continue following the loop statement. And although also continue statement exits the loop immediately, but will exit the loop from the top of the cycle

Ministry to continue.

Copy the code
var n = 0;
for (var i=1; i < 10; i++) {
if (i % 5 == 0) {
continue;
}
a ++;
}
alert(num); //8
Copy the code

 

 

Copy the code
var n = 0;
outermost:
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
if (i == 5 && j == 5) {
break outermost;
}
a ++;
}
}
alert(num); //55
Copy the code

Adding this tag will result will not only lead to a break statement to exit within the
Ministry for the statement (that is, using a variable j loop), but also withdraw from the outside for the statement (that is, using a loop variable i).

 

Copy the code
var n = 0;
outermost:
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
if (i == 5 && j == 5) {
continue outermost;
}
a ++;
}
}
alert(num); //95
Copy the code

 continue statement forces continue the cycle - to exit the inner loop, the outer loop.

Guess you like

Origin www.cnblogs.com/ffm009/p/11682181.html