Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Sunday 26 June 2011

Nested switch statement in java


Nested switch:
                         We can use a switch as part of the statement sequence of an outer switch. This is called nested switch. We know that each switch defines its own block of code but case constants of outer switch have no conflicts with the inner switch's case constants.

General syntax:
                           switch (value)
                           {
                            case 1:
                               switch (value)
                               {
                                case 1:
                                statement(s)
                                break;
                                .
                                .
                                case n:
                                statement (n)
                                break;
                                default:
                                statement
                                }
                          case 2:
                          statement(s)
                          break;
                          .
                          .
                          case n:
                          statement (n)
                          break;
                          default:
                          statement
                         }    
Here, value can be a variable or any constant value. Remember case 1 of outer switch have no conflicts with case 1 of inner switch. If the value matches with case 1 (outer switch's) then inner switch will be executed otherwise it will be bypassed.


No comments:

Post a Comment

Share