1 package com.ibeve.demo; 2 3 public class WhileDemo { 4 public static void main(String[] args) { 5 6 /** 7 * Define initialization expression; while(conditional expression) { loop body (execute statement ) } 8 */ 9 int x = 1 ; 10 // while (x < 13) { 11 // System.out.println("x=" + x); 12 // x = x + 2; 13 // } 14 15 do { 16 System.out.println("do : x=" +x); 17 x++ ; 18 } while (x < 0 ); 19 20 int y = 1 ; 21 while (y < 0 ) { 22 System.out.println("y=" + y); 23 y++ ; 24 } 25 26 /** 27 * while: Judge the condition first, and execute the loop body only if the condition is met. 28 * do while: execute the loop body first, then judge the condition, if the condition is satisfied, then continue to execute the loop body. 29 * Simple sentence: do while The body of the loop is executed at least once regardless of whether the condition is met or not. 30 */ 31 } 32 }