This article mainly analyzes the Label statements in Javascript through instance comparison, which has good reference value. If you need a friend, let's take a look at the Label statement. The syntax described in the book is:
For example, begin: for (var I = 0; I <10; I ++) {alert (I );}
A typical example shows the Label application: (no Label is added)
var num = 0; for (var i = 0 ; i < 10 ; i++){ for (var j = 0 ; j < 10 ; j++){ if( i == 5 && j == 5 ){ break; } num++; } }
Alert (num); // The loop jumps out of the j loop when I is 5 and j is 5, but continues to execute the I loop and outputs 95
Compare the program after Label is used: (After Label is added)
Var num = 0; outPoint: for (var I = 0; I <10; I ++) {for (var j = 0; j <10; j ++) {if (I = 5 & j = 5) {break outPoint;} num ++ ;}} alert (num); // The loop is 5 in I, when j is set to 5, the system jumps out of the double loop and returns to the outPoint layer for further execution. The output is 55.
The break and continue statements are used for comparison:
var num = 0; outPoint: for(var i = 0; i < 10; i++) { for(var j = 0; j < 10; j++) { if(i == 5 && j == 5) { continue outPoint; } num++; } } alert(num); //95
From the value of alert (num), we can see that the function of the continue outPoint; statement is to jump out of the current loop and jump to the for loop under the outPoint (TAG) to continue execution.
The above is all the content of this article. I hope this article will help you in your study or work, and I also hope to support PHP!
For more information about the Label statements in Javascript, see the PHP Chinese website!