Thursday, 10 March 2016

Nested Switch in Java

How Nested Switch work in Java


               We can use the switch inside another switch as like the same way we use Nested-if conditions. Use switch as a part of statement sequence of an outer switch. This is called Nested Switch. Each switch has its own block hence there is no conflicts between the inside and outside switches

General Model of Nested Switch


switch(outer)
{
     case 1:

          System.out.println("Outer Switch");
          break;

     case 2:
          switch(inner)
          {
               case 1:
                    System.out.println("Inner Switch");
                    break;

               case 2:
                    System.out.println("Inner Switch case 2");
                    break;

               default:
                    System.out.println("Outer Switch");
                     break;
          }

     default:
          System.out.println("Outer Switch");
          break;
}
          

Important features of Switch Statements

  • The switch differs from the if statement in that switch can only test for equality, whereas if can evaluate any type of Boolean expression. That is, the switch looks only for a match between the value of the expression and one of its case constants.
  • No two case constants in the same switch can have identical values. Of course, a switch statement and an enclosing outer switch can have case constants in common.
  • A switch statement is usually more efficient than a set of nested ifs.

2 comments :

  1. Thank you for sharing the information with the java. Really amazing to read this content.

    Web Designing Training in Chennai

    ReplyDelete
  2. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

    ReplyDelete