带标签的break与continute

标签语句是在某个语句前面加上个标识符以及一个冒号 . 标签在 breakcontinue 语句中会被使用到 .

Break+ 标签 :           跳出标签所标注的那个语句 , 然后去执行后续语句 .

Continue+ 标签 :     停止 continue 语句的后续语句的执行 , 跳到标签所标注的语句去执行下一循环 .

测试代码 复制代码
  1. /**   
  2.  * @(#)BreakAndContinueTest.java   
  3.  * @author  fhd001   
  4.  * @version 1.00 2009/6/14  
  5.  */   
  6.   
  7.   
  8. public class BreakAndContinueTest {   
  9.   
  10.     public BreakAndContinueTest() {}   
  11.        
  12.     public static void main (String[] args) {   
  13.            
  14.         String[]strs = new String[]{"111","222","333","444","555","666"};   
  15.            
  16.         System.out.println ("---continue test---");   
  17.            
  18.         continueTest:for(String str:strs){   
  19.             if("444".equalsIgnoreCase(str)){   
  20.                 continue continueTest;   
  21.             }   
  22.             System.out.println (str);   
  23.         }   
  24.            
  25.         System.out.println ("-----break test-----");   
  26.            
  27.         breakTest:for(String str1:strs){   
  28.             if("444".equalsIgnoreCase(str1)){   
  29.                 break breakTest;   
  30.             }   
  31.             System.out.println (str1);   
  32.         }   
  33.     }   
  34. }  
/**
 * @(#)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);
    	}
    }
}

 

测试结果代码 复制代码
  1. --------------------Configuration: <Default>--------------------   
  2. ---continue test---   
  3. 111  
  4. 222  
  5. 333  
  6. 555  
  7. 666  
  8. -----break test-----   
  9. 111  
  10. 222  
  11. 333  
  12.   
  13. Process completed.  
--------------------Configuration: <Default>--------------------
---continue test---
111
222
333
555
666
-----break test-----
111
222
333

Process completed.

  转http://fhd001.iteye.com/blog/408075

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值