返回列表 發帖

continue, break, return (二)

break 語法能強制程序立即跳出所在迴圈.
  1. public class Ch27
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=10; i++)
  6.         {
  7.              if(i==5)
  8.                  break;
  9.              System.out.println(i);
  10.         }
  11.         for(int i=1; i<=10; i++)
  12.         {
  13.              System.out.println(i);
  14.         }
  15.     }
  16. }
複製代碼

  1. public class Ch27
  2. {
  3.   public static void main(String args[])
  4.   {
  5.     for(int i=1; i<=10; i++)
  6.     {
  7.       if(i==5)
  8.          break;
  9.       System.out.println(i);
  10.     }
  11.     for(int j=1; j<=10; j++)
  12.     {
  13.       System.out.println(j);
  14.     }
  15.   }
  16. }
複製代碼

TOP

  1. public class Edit2
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=10; i++)
  6.         {
  7.              if(i==5)
  8.                  break;
  9.              System.out.println(i);
  10.         }
  11.         for(int i=1; i<=10; i++)
  12.         {
  13.              System.out.println(i);
  14.         }
  15.     }
  16. }
複製代碼
我是眾神之王XXX  I love you
0000000000

TOP

  1. public class Ch26
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=10; i++)
  6.         {
  7.             if(i==5)
  8.                 break;
  9.             System.out.println(i);
  10.         }
  11.         for(int i=1; i<=10; i++)
  12.         {
  13.              System.out.println(i);
  14.         }
  15.     }
  16. }
複製代碼

TOP

  1. public class Ch21
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=100; i++)
  6.         {
  7.              if(i==50)
  8.              break;

  9.              System.out.println(i);
  10.         }
  11.         for(int i=1; i<=100; i++)
  12.         {
  13.              System.out.println(i);
  14.         }
  15.     }
  16. }
複製代碼

TOP

返回列表