返回列表 發帖

while 迴圈

本帖最後由 tonyh 於 2012-10-8 21:29 編輯
  1. public class ch15
  2. {
  3.   public static void main (String args[])
  4.   {
  5.       int i=1;     //初始值
  6.       while(i<=10)       //終止值
  7.       {
  8.            System.out.println(i);
  9.            i++;       //遞增或遞減
  10.       }
  11.   }
  12. }
複製代碼
  1. public class ch15
  2. {
  3.   public static void main (String args[])
  4.   {
  5.       int i=1;     //初始值
  6.       while(true)       //當條件為true, 將造成無窮迴圈
  7.       {
  8.            System.out.println(i);
  9.            i++;       //遞增或遞減
  10.       }
  11.   }
  12. }
複製代碼

返回列表