Computer Science, asked by sreeja3, 1 year ago

write about break statement and write syntax for it.

Answers

Answered by priyanka05
0

The break statement in Java programming language has the following two usages −

When the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.It can be used to terminate a case in the switch statement.


syntax
 

p
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");

      }

   }

}

Answered by SurajSaraf
0
'break;' this statement normally use in the 'if' ,'else' ,'switch case' type function.

When a program run then it take data line by line. But some time we need to come out from this statement and not to run this statement again then we use break statement.

like a example 

[

switch(a)
{
case 1:
/*your statement*/
break;
case 2:
/*your statement*/
break;
default:
/*your statement*/
}
]

here will happen that when you press 1 then 
without break it take you from one to upto last  statement(default)

with break it will come back from case 1 and take you in the next line of your default statement (after ending the '}' bracket of switch statement).

if you don't understand then you can sms me personally i will show you via image or diagram.   


   
Similar questions