c - 如何编写继续程序;使用C

标签 c continue

如何在不实际使用 continue 语句的情况下执行代码。 换句话说,我怎样才能编写一个程序来继续;声明而不使用“继续;” (继续的定义;)。

提前致谢

int a = 10;
while(a < 20){
  if(a == 15){
    a = a+1;
    continue;   
  }
  print ("%d", a);
  a++;
}

最佳答案

请注意,这里的 else 语句具有适当的作用域,它模拟了 continue 语句将执行的操作(即跳到 while 循环的末尾)。我特意保留了其余代码不变。

int a = 10;
while(a < 20){
  if(a == 15){
    a = a+1;
//    continue;   
  } else {
    print ("%d", a);
    a++;
  }
}

或者如果你想激起 C 诸神的愤怒

int a = 10;
while(a < 20){
  if(a == 15){
    a = a+1;
//    continue;   
    goto next;  // Really - don't do this...
  }
  print ("%d", a);
  a++;
next:
  }
}

关于c - 如何编写继续程序;使用C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55839967/

相关文章:

java - Cap'n Proto - 在 Java 中查找消息大小

javascript - 为什么这个 while 语句会创建无限循环?

C# - while 循环内的 foreach 循环 - 中断 foreach 并立即继续 while 循环?

python - 我怎样才能回到循环的开头?

c++ - 在 C++ 中 : Is it possible to have a named enum be continued in a different file?

C运算符 "<<"

c - 为什么这个C程序需要这样的表达式

c - 如何在 C 中使用 'fread' 从文件中读取并获取分离的数据?

c++ - C/FORTRAN 将双下溢设置为零

loops - Applescript 相当于 "continue"?