I have read through what seems to be all the Nested Switch topics here, plus a few on other C/C++ forums and nobody seems to address the situation of trying to have a "default" case in both the main and nested switch. My main outer switch has too many possible cases to code each one so a default is a must. The same possible input values are available to the inner case, so another default case is a must.
MAIN QUESTION: It seems that only one "default" is allowed no matter how many nested cases you have?
If I comment out either default case the code will compile but it won't act as desired.
outer switch( first command ); // send some command via Serial Monitor
inner switch( second command )
do other stuff;
Serial.println("invalid second command");
} //end inner switch
} //end case A. Extra bracket set around case A code did not help.
do other thing;
// Serial.println("invalid first command");
- if 'first command' doesn't match 'A', 'B', 'a', or 'b' the inner default will execute.
- if 'first command' matches any of the cases that case will execute.
- For example, first command == a then case A "do thing" does NOT happen but inner case a "do stuff" does happen.
I assume the answer is going to be change the inner switch to If Else statements but maybe there's something special to properly using nested switches so they don't act like one big switch and have duplicate case conflicts?