![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
asajay Guest
|
Can I code nested switch statements? |
Posted: Fri Oct 05, 2001 4:57 pm |
|
|
I think I hit a snag when trying to nest some switch cases.
ie.
switch (module)
{
case mod1:
code;
code;
break;
case mod2:
switch (cmd)
{
case 1:
code;
code;
break;
case 2;
code;
break
}
break;
}
I can't seem to get to work. The first switch case drops me into the proper module, but the next switch doesn't appear to execute and drop me into the proper command.
Is there a problem nesting switch statements like this, with the CCS compiler?
Thanks,
Asa Jay
___________________________
This message was ported from CCS's old forum
Original Post ID: 556 |
|
![](templates/subSilver/images/spacer.gif) |
Dave Yeatman Guest
|
Re: Can I code nested switch statements? |
Posted: Fri Oct 05, 2001 5:40 pm |
|
|
Asa,
I have no problem with multiple nested switch statements. The only thing I do differently is to enclose the sub-switch statement in curly braces within the case test as I have shown in your modified code below. BTW, as a rule I always enclose my case sub-statements in braces to improve readability and appears to help me avoid this type of problem as a bonus!
Dave
*********************************
:=
:=switch (module)
:={
:= case mod1:
:= code;
:= code;
:= break;
:= case mod2:
{ // begin of case (mod2)
:= switch (cmd)
:= {
:= case 1:
:= code;
:= code;
:= break;
:= case 2;
:= code;
:= break
:= } // end switch (cmd)
} // end case (mod2)
break;
:=}
:=
:=I can't seem to get to work. The first switch case drops me into the proper module, but the next switch doesn't appear to execute and drop me into the proper command.
:=
:=Is there a problem nesting switch statements like this, with the CCS compiler?
:=
:=Thanks,
:=Asa Jay
___________________________
This message was ported from CCS's old forum
Original Post ID: 557 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|