nesting switch?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaleeswaran
    New Member
    • Mar 2007
    • 132

    nesting switch?

    hi
    can we use switch inside another switch statement...?
    i am doing banking program.i tried to call another switch statement with in switch statement but it show error.
    clarify my doupt plzzzzzzzzzz
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by kaleeswaran
    hi
    can we use switch inside another switch statement...?
    i am doing banking program.i tried to call another switch statement with in switch statement but it show error.
    Yes you can do that; a switch statement is just another statement which can
    occur where all other statements could've been located.

    I advise you not to do that unless you like jumpy, unreadable wall paper code.
    Better create another method that takes care of the inner switch.

    kind regards,

    Jos

    Comment

    • BSCode266
      New Member
      • Jan 2007
      • 38

      #3
      I think it kinda looks funny, switched switches, but indeed i would not use them. Perhaps make a method that does the smaller switches. Here is the correct syntax:

      Code:
      switch(state) {
        case 0: switch(state2) {
                      case 0: state = 2;
                      case 1: state =12343854686434;
                      };
        case 1: etc etc;
      }
      BSCode266

      Comment

      • kaleeswaran
        New Member
        • Mar 2007
        • 132

        #4
        fine thank you,

        Comment

        Working...