天天看點

Java 基礎 之 while 循環

http://www.verejava.com/?id=16992618818220
/*
while 循環
while(表達式){} 如果表達式為true 繼續執行,否則退出循環
*/

public class Test1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // 輸出 1 - 5 之間(包括 1,5 本身)的數.
        int n=1;
        while(n<=5) // while 判斷條件true 執行循環代碼, 否則終止循環
        {
            System.out.println(n);
            n++;
        }
        
    }
}