while 循环

while是最基本的循环,它的结构为:

1
2
3
while( 布尔表达式 ) {
  //循环内容
}

只要布尔表达式为 true,循环体会一直执行下去。

实例

Test.java 文件代码:

1
2
3
4
5
6
7
8
9
10
public class Test {
   public static void main(String args[]) {
      int x = 10;     
      while( x < 20 ) {
      System.out.print("value of x : " + x );   
       x++;       
      System.out.print(" ");   
 }
 }
 }

以上实例编译运行结果如下:

点击链接查看更多

原文地址:https://www.cnblogs.com/hane/p/7356771.html