码迷,mamicode.com
首页 > 其他好文 > 详细

for循环与while循环组合使用

时间:2015-09-29 13:17:45      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

适用于内层while循环中的产生的某个条件依赖于外部的for循环

例子如下

public class Test {
     public static void main(String[] args) throws InterruptedException {
          Random rand = new Random();
          int[] str = {1,2,3,4};
          for(int i=0;i<str.length;i++){
          System.out.println("跳出while循环"+str[i]);
          E:while(true){
         Thread.sleep(2000);
          int j = rand.nextInt(str[i]+1);
          System.out.println("j"+j);
          switch (j) {
          case 1:
               System.out.println(str[i]);
               break E;
          case 2:
               System.out.println(str[i]);
                break;
          case 3:
                System.out.println(str[i]);
                break E;
          default:
               break;
           }
       }
    }
  }
}

for循环与while循环组合使用

标签:

原文地址:http://my.oschina.net/u/1169535/blog/512248

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!