CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Can I code nested switch statements?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asajay
Guest







Can I code nested switch statements?
PostPosted: Fri Oct 05, 2001 4:57 pm     Reply with quote

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
Dave Yeatman
Guest







Re: Can I code nested switch statements?
PostPosted: Fri Oct 05, 2001 5:40 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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