switch中的case中如果有深层的if语句,如果想退出swich语句,则用break,不管它是在多么深层的if语句中,都会退出当前case。如果想直接退出函数,则直接用return。例子如下:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;
int i = 1;
ptr = strstr(str1, str2);
printf("The substring is: %s/n", ptr);
switch(i)
{
case 1:
if(1)
{
if(1)
{
printf("if if/n");
return;
}
}
else
{}
printf("out if/n");
break;
case 2:
printf("case 2/n");
break;
}
printf("main over/n");
}