This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Please help baby C programmer...
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: Ron Hudson <rhudson at cnonline dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 27 Jan 2002 18:11:31 +0100
- Subject: Re: Please help baby C programmer...
- References: <3C543148.206@cnonline.net>
Ron Hudson wrote:
> I am having trouble with the switch / case statement.
>
> In my program I have a nested case statement.
>
> Is is OK to nest switch statements?
Sure! The following implementation of your pseudocode both compiles and run as
expected
(just remember to put a break; also after the end of each of the inner swithes
(if I understand well your intention))
#define AA 1
#define BB 1
int main()
{
int a = AA;
int b = BB;
switch (a){
case 1:
switch (b){
case 1:
printf("a1b1\n");
break;
case 2:
printf("a1b2\n");
break;
} /* close switch b */
break;
case 2:
switch (b){
case 1:
printf("a2b1\n");
break;
case 2:
printf("a2b2\n");
break;
} /* close switch b */
break;
}/* close switch a */
return 0;
}