Java 语法 索引 ----- 循环(loop)

While 和  Do-While

//while
int i = 0;

while (i < 10) {
    
        System.out.print(i++);

}

//do - while 

int i = 0;
do { 
     System.out.print(i++);
 } while ( i < 10 );

 

For 和 Foreach

for (int i = 0; i < 10; i++){ 
     System.out.print(i); 
}

for (int k = 0, l = 10; k < 10; k++, l--){ 
     System.out.print(k + l); 
}
int[] array = { 1,2,3 };

for (int element : array) { 
    System.out.print(element); 
}

 

中断循环

myLoop: for (int i = 0, j = 0; i < 10; i++) {
              while (++j < 10) {
                  break myLoop; // end for
                  continue myLoop; // start next for
             }
         }
posted @ 2014-08-09 02:18  星月石  阅读(348)  评论(0编辑  收藏  举报