while循环和do/while循环

版权声明:ByRisonBoy https://blog.csdn.net/Rison_Li/article/details/83153397

1、while循环

先判断再执行:

public static void main(String[] args){
		  int x = 0;
	      while( x < 3 ) {
	         System.out.println("value of x : " + x );
	         x++;
	      }
	   }

结果:

2、do while循环

先执行在判断,至少执行一次。

​
public static void main(String[] args){
		  int x = 0;
	      while( x < 3 ) {
	         System.out.println("value of x : " + x );
	         x++;
	      }
	   }

结果:

猜你喜欢

转载自blog.csdn.net/Rison_Li/article/details/83153397