Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
switch子句中的while语句_C_While Loop_Switch Statement - Fatal编程技术网

switch子句中的while语句

switch子句中的while语句,c,while-loop,switch-statement,C,While Loop,Switch Statement,这个问题来自我的C语言考试。它要求得到结果 #include <stdio.h> int main() { int a = 4, b = 30; printf("%d\n", a); switch(a){ case 1: a = a*10; break; case 2: a = a*10; break; case 3: a = a*10; while (a<b) case 4: {a =

这个问题来自我的C语言考试。它要求得到结果

#include <stdio.h>

int main()
{
    int a = 4, b = 30;
    printf("%d\n", a);

    switch(a){
        case 1: a = a*10; break;
        case 2: a = a*10; break;
        case 3: a = a*10;
        while (a<b) case 4: {a = a+5;} break; //???
        case 5: a = a*10; break;
        default:
            b = a*10;break;
    }
    printf("%d\n", a);

    return 0;
}
#包括
int main()
{
INTA=4,b=30;
printf(“%d\n”,a);
开关(a){
案例1:a=a*10;断裂;
案例2:a=a*10;断裂;
情况3:a=a*10;
而
如果你想变得聪明,省略
中断
,在
中断
和下一个
案例
之间插入指令……你必须知道自己在做什么。其他阅读代码的人可能很难解释它

这也意味着不要在一个循环结构的中间跳跃或类似的奇怪事物。


如果你在现实生活中遇到这样的代码,重写它。等效的方法是使用
do
while
指令(跳过第一个测试,即使
aI感觉到你的痛苦,我们也可以进入循环。我从1991年开始编写C,我从来没有做过这样不可读的构造。这个考试是胡说八道的。跳进身体一会儿()循环是一种非常糟糕的编程实践。强烈建议不要使用这样的代码结构
while (a<b) case 4: {a = a+5;} break; 
  switch(a)
  {
    case 1: a = a*10; break;
    case 2: a = a*10; break;
    case 5: a = a*10; break;
    default:
        b = a*10;break;
}
case 4: do {a = a+5;} while (a<b); break; 
while (a<b) case 4: {a = a+5;} break; //???
while (a<b) 
some_label:
{
   a = a+5;
}
break; //This will break out of the surrounding switch.