1.

What is the purpose of break keyword while using switch case statement ? Illustrate with the help of an example.

Answer»

The break statement stops the flow of logic within the switch statement and the statement immediately following the switch is executed.

OR

The break statement prevents "fall through" in the switch statement.

Example:

switch (n)

{

case 10:

System.out.printIn ("Ten") ;

break;

case 20:

System.out.printIn ( "Twenty") ;

break;

default;

System.out.printIn("Not Ten or Twenty") ;

}



Discussion

No Comment Found