Today, when I was looking at an open-source project, I accidentally saw an unfamiliar syntax and usage. So I checked the information and wrote a demo for verification. The result is as follows:
Anyone who knows C ++ knows the word "Goto". This keyword allows us to jump flexibly in the program. Of course, it is not recommended, but he also has his specific purpose. For example, it is particularly useful when multiple loops are exceeded:
Public class main {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Init ();
}
Private Static void Init (){
For (Int J = 0; j <30; j ++ ){
For (int A = 0; A <30; A ++ ){
If (A = 15)
Break label;
System. Out. println ("third ====" + );
}
System. Out. println ("second ====" + J );
}
System. Out. println ("first =" + I );
}
System. Out. println ("End ==== ");
}
}
The output result is:
Third ====== 0
Third ====== 1
Third ======= 2
Third ===== 3
Third ======= 4
Third ====== 5
Third ====== 6
Third ====== 7
Third ====== 8
Third ===== 9
Third ====== 10
Third ====== 11
Third =====12
Third =====13
Third =====14
End ======
We can see that after the label is set before the recycling starts, you can use the break label in the internal loop to jump out of all the loops and then execute the code after the outgoing loop. Another usage is the continue label.
The continue label is used to jump out of all loops and return to the start of the outermost loop to re-start the execution of the circular code.