Java break statement Question 1

Question

What is the output of the following code?


public class Main 
{
   public static void main(String[] args)
   {//from w  w  w.  j a v  a 2s. c om
      int count; // control variable also used after loop terminates
      
      for (count = 1; count <= 10; count++) // loop 10 times
      {  
         if (count == 5)  
            break; 

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

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


1 2 3 4 
Broke out of loop at count = 5



PreviousNext

Related