码迷,mamicode.com
首页 > 编程语言 > 详细

java 循环控制

时间:2018-06-04 21:26:34      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:str   info   date   for   ber   技术分享   pre   bubuko   inf   

while 循环

while(condition){
       //xxx
}

技术分享图片


for循环

for(initialization;expression;update){//注意是分号的
    //xxxx
}


      for(int x = 10; x < 20; x = x + 1) {
         System.out.print("value of x : " + x );
         System.out.print("\n");
      }

技术分享图片


do{
    //xxxx
}while(condition);

int x = 10;
      do {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");
      }while( x < 20 );

技术分享图片


循环控制声明
break
技术分享图片

int [] numbers = {10, 20, 30, 40, 50};

      for(int x : numbers ) {
         if( x == 30 ) {
            break;
         }
         System.out.print( x );
         System.out.print("\n");
      }

continue
技术分享图片

int [] numbers = {10, 20, 30, 40, 50};

      for(int x : numbers ) {
         if( x == 30 ) {
            continue;
         }
         System.out.print( x );
         System.out.print("\n");
      }

java 循环增强

for(declaration : expression) {
   // Statements
}

public class Test {

   public static void main(String args[]) {
      int [] numbers = {10, 20, 30, 40, 50};

      for(int x : numbers ) {
         System.out.print( x );
         System.out.print(",");
      }
      System.out.print("\n");
      String [] names = {"James", "Larry", "Tom", "Lacy"}; //大括号

      for( String name : names ) {
         System.out.print( name );
         System.out.print(",");
      }
   }
}

技术分享图片

java 循环控制

标签:str   info   date   for   ber   技术分享   pre   bubuko   inf   

原文地址:https://www.cnblogs.com/cyany/p/9135383.html

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