首页 > 代码库 > Java 语法 索引 ----- 循环(loop)

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

While 和  Do-While

//whileint 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             }         }