java中while语句加不加{}的区别

来源:互联网 发布:wav播放软件 编辑:程序博客网 时间:2024/05/16 10:23


 public class Test {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
     int i = 0;
     while(i != 10)
         System.out.println(i);
         i ++;
     

 }

//此时,控制台将持续打出0 ,0, 0 .......;当我们给while加上{}的时候,

      while(i != 10){
          System.out.println(i);
          i ++;

      }

//控制台将打出0,1,2,...9,由此可以知道,while中不加{}的话只循环运行第一条语句,循环结束后再运行之后的。

0 0