为什么每次switch结束后就跳出程序了,break不是只对小循环起作用吗

#include

#include

#include

#include"BASE.h"

#include"fun_5.h"

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

 

int main(int argc, char *argv[]){

int n,q;

while(1){

printf("Enter 1 to start the program\n");

scanf("%d",&q);

/*if cycle*/

if (q==1){

/*enter function*/

printf( "1.Decimal to Binary\n2Make a pattern output\n3.Determine what triangle it is\n4.Sum of any two digit number\n5.What is the volume of the sphere\n6.How many leap years have you been born\nPlease choose\n");

scanf("%d",&n); 

/*switch cycle*/

switch(n){

case 1:{

    int n,h;

    printf("Please input the number\n");

    scanf("%d",&n);

    h=DecimalToBinary(n);

printf("%d\n",h);

    break;}

case 2:{

    double radius;

 printf("enter radius:");

 scanf("%lf",&radius);

 printf("Volume=%lf\n",Volume(radius));

    break;}

}

}

else

printf("Input error");

break;

}

 return 0;

}

最下面的break因该是else的代码块。else下面的两行加大括号

switch的break是跳出当前的switch
break并不只对循环有用哦

break结束了之后跳出了switch,接着执行下一步(也就是在else之后执行,但是呢你的else之后并没有要继续的操作,所以就退出了),你这里写的是if else 结构,如果你输入的q==1,那就执行switch,如果不是就执行else。

如果你再在return 0 的前边加一些执行语句,那跳出break之后就会接着执行这些语句。你可以在return0,前边加一个 printf语句试一下