void func1()
{
int a = 5;
SWITCH:
sleep(1);//无实际意义仅作延迟
switch(a)
{
case 1:
printf("case 1\n");
break;
case 2:
printf("case 2\n");
break;
case 3:
printf("case 3\n");
break;
default:
printf("goto switch %d\n", a);
goto SWITCH;
}
}
void func2()
{
int a = 5;
while(1)//for(;;;)也可以
{
sleep(1);//无实际意义仅作延迟
switch(a)
{
case 1:
printf("case 1\n");
break;
case 2:
printf("case 2\n");
break;
case 3:
printf("case 3\n");
break;
default:
printf("goto switch %d\n", a);
break;
}
}
}
int main(int argc, char *argv[])
{
//func1和func2这两种方法都可以
func1();
func2();
return 0;
}