标签语句是在某个语句前面加上个标识符以及一个冒号 . 标签在 break 与 continue 语句中会被使用到 .
Break+ 标签 : 跳出标签所标注的那个语句 , 然后去执行后续语句 .
Continue+ 标签 : 停止 continue 语句的后续语句的执行 , 跳到标签所标注的语句去执行下一循环 .
- /**
- * @(#)BreakAndContinueTest.java
- * @author fhd001
- * @version 1.00 2009/6/14
- */
- public class BreakAndContinueTest {
- public BreakAndContinueTest() {}
- public static void main (String[] args) {
- String[]strs = new String[]{"111","222","333","444","555","666"};
- System.out.println ("---continue test---");
- continueTest:for(String str:strs){
- if("444".equalsIgnoreCase(str)){
- continue continueTest;
- }
- System.out.println (str);
- }
- System.out.println ("-----break test-----");
- breakTest:for(String str1:strs){
- if("444".equalsIgnoreCase(str1)){
- break breakTest;
- }
- System.out.println (str1);
- }
- }
- }
/** * @(#)BreakAndContinueTest.java * @author fhd001 * @version 1.00 2009/6/14 */ public class BreakAndContinueTest { public BreakAndContinueTest() {} public static void main (String[] args) { String[]strs = new String[]{"111","222","333","444","555","666"}; System.out.println ("---continue test---"); continueTest:for(String str:strs){ if("444".equalsIgnoreCase(str)){ continue continueTest; } System.out.println (str); } System.out.println ("-----break test-----"); breakTest:for(String str1:strs){ if("444".equalsIgnoreCase(str1)){ break breakTest; } System.out.println (str1); } } }
- --------------------Configuration: <Default>--------------------
- ---continue test---
- 111
- 222
- 333
- 555
- 666
- -----break test-----
- 111
- 222
- 333
- Process completed.
--------------------Configuration: <Default>-------------------- ---continue test--- 111 222 333 555 666 -----break test----- 111 222 333 Process completed.