Java programming
30.6K subscribers
131 photos
12 files
20 links
Download Telegram
In the above-mentioned code, you can see that the do while loop will execute the condition once, for sure.

Now, let’s hop onto our next segment, Infinite do-while loop in Java.

Infinite do-while loop in Java
Infinite do-while loop in Java is similar to the infinite while loop. You can refer a section of my previous blog –Infinite while Loop in Java.
What is a Switch Case In Java?

Java programming language has conditional and control statements which optimizes the logic while writing a program. Hustle free logic building using the switch case results in improved efficiency. Using a switch case in java optimizes the readability of the code while working on multiple test expressions. In this article, you will learn about switch case in java with various examples.

What Is A Switch Case In Java?

Java switch statement is like a conditional statement which tests multiple values and gives one output. These multiple values that are tested are called cases. It is like a multi-branch statement. After the release of java 7 we can even use strings in the cases. Following is the syntax of using a switch case in Java.
Rules To Remember
There are a certain rules one must keep in mind while declaring a switch case in java. Following are a certain points to remember while writing a switch case in java.

1 We cannot declare duplicate values in a switch case.

2 The values in the case and the data type of the variable in a switch case must be same.

3 Variables are not allowed in a case, it must be a constant or a literal.

4 The break statement fulfills the purpose of terminating the sequence during execution.

5 It is not necessary to include the break statement, the execution will move to the next statement if the break statement is missing.

6 The default statement is optional as well, it can appear anywhere in the block.
public class Example{
public static void main(String args[]){
int month= 7;

switch(month){
case 1 :
System.out.println("january");
break;
case 2:
System.out.println("february");
break;
case 3:
System.out.println("march");
break;
case 4:
System.out.println("april");
break;
case 5:
System.out.println("may");
break;
case 6:
System.out.println("june");
break;
case 7:
System.out.println("july");
break;
case 8:
System.out.println("august");
break;
case 9:
System.out.println("september");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("november");
break;
case 12:
System.out.println("december");
break;
default:
System.out.println("not valid");
}
}
}

Output: july
Nested Switch Case
Nested switch case incorporates another switch case in an existing switch case. Following is an example showing a nested switch case.
Fall Through Switch Case
Whenever there is no break statement involved in a switch case block. All the statements are executed even if the test expression is satisfied. Following is an example of a fall through switch case.
Enum In Switch Case
Switch case allows enum as well. Enum is basically a list of named constants. Following is an example of the use of enum in a switch case.
String In Switch Case
After the release of Java 7, a switch case can have strings as a case. Following is an example of using string as cases in a switch statement.
The Coming chapter: JAVA CORE CONCEPT