Skip to main content

Posts

Showing posts from January, 2023

Java Switch keyword

Java switch keyword is used to provide multiple branching in a program. It tests the value of a variable and compares it with multiple case values. If there is a match, the associated block of code is executed. The break keyword is used to terminate the switch statement and control passes to the next line of code after switch. If none of the cases match the value of the variable, then the default label is executed. The default label must be present in every switch statement. If there is no default label, and if none of the cases match, then no action takes place and control passes to the next line of code after switch. The syntax for using Java switch keyword is given below: switch(expression) { case value1: //if expression == value1 //execute this block break; //terminates this particular case case value2: //if expression == value2 //execute this block break; //terminates this particular case //you can have any number of cases in a switch statement default: //executes this block if no...