do-while

/**
 *  需求:基本练习,do-while
 *  思路:略
 *   
 *  步骤:略
 */public class Demo_1{
    public static void main(String[] arge) {
        int x=1;
  do{
      System.out.println("x="+x);
      x++;
      }
while(x<1);
    }
}


while


/**
 *  需求:基本练习,do-while
 *  思路:略
 *   
 *  步骤:略
 */
public class Demo_1{
    public static void main(String[] arge) {
        int y=0;
        while(y<1){
            System.out.println("y="+y);
            y++;
        }
    }
}


两者的区别在于第一圈循环时,while是判断循环条件的,再循环,而do-while 则是先执行后判断,所以,第二个程序先打印10,然后I++然后跳出循环。
This moment will nap, you will have a dream; but this moment study, you will interpret a dream.
原文地址:https://www.cnblogs.com/mawenqi-barry/p/7604782.html