集册 Java实例教程 Break语句退出for语句。

Break语句退出for语句。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

588
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Break语句退出for语句。

public class Main 

{

   public static void main(String[] args)//nowjava.com - 时代Java 提供

   {

      int count; // control variable also used after loop terminates

      

      for (count = 1; count <= 10; count++) // loop 10 times

      {  

         if (count == 5)  

            break; // terminates loop if count is 5


         System.out.printf("%d ", count);

      }


      System.out.printf("%nBroke out of loop at count = %d%n", count);

   } 

}