switch(a)
{
case 1:printf("\n");
break;
case 2:printf("\n");
break;·····
default: printf("\n");
break;
}
switch(){ }语句中,花括号{ }里面的任何break都只能跳出该switch语句。想要跳出更大的循环体,所以需要采用一个比较巧妙的方式进行。
#include <stdio.h>
int main()
{
int a=0,b=0,c=0;
int d=0;
int status = 0;
do
{
switch(status)
{
case 1: status = 2; break;
case 2: status = 2; break;
case 3: status = 4; break;
default: d=1;
break; /*这个break无法跳出do_while循环,去执行想要执行的printf*/
}
if(d==1)break;
} while(1);
printf(" ...",a,b,c);}
if(d==1)break;跳出do_while循环结构。