Tuesday, 3 November 2020

The Break Keyword in JAVA

 

 

The Break Keyword in JAVA :-


The break keyword is used  to stop the entire loop.  The break keyword must be used inside  any  loop or  a switch statement. The break  keyword  will stop the execution  of the innermost  loop and start  execcuting  the next  line of code  after the block .  

The syntax of a break  is a single  statement inside  any loop :

     break;



Example :-


 public class Test 

{

   public static void main(String  args[])

   {

       int [] numbers = {10,20,30,40,50};

        for(int x : numbers)

         {

              if (x == 30)

              {

                  break;

               }

            System .out.print(x);

             System.out.print("\n");

           

            }

 

       }

 

}

       

 OUTPUT :-

10

20

 

 

No comments:

Post a Comment

Student Marks Calculation app using java

      import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...