JAVA循环结构

一.while循环

while(布尔表达式)

{

//代码语句

}

和C#一致

二.do...while..循环

do{

代码语句 }while(布尔表达式)

在判断条件之前已经执行的代码语句,如果布尔表达式为true,则重复执行代码语句,直到布尔表达式为false.

如果布尔表达式为false,则只执行一遍代码语句.

三.for 循环

for(初始条件;循环条件;状态改变)

{循环体,代码语句}

和C#一致

四.遍历(java增强for循环)

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("
");
      String [] names ={"James", "Larry", "Tom", "Lacy"};
      for( String name : names ) {
         System.out.print( name );
         System.out.print(",");
      }
   }
}

输出结果:

10,20,30,40,50,

James,Larry,Tom,Lacy,

原文地址:https://www.cnblogs.com/zhangxin4477/p/7473957.html