continue 语句 (C++)
强制转移对最小封闭 do、for 或 while 循环的控制表达式的控制。
语法
continue;
备注
将不会执行当前迭代中的所有剩余语句。 确定循环的下一次迭代,如下所示:
在
do
或while
循环中,下一个迭代首先会重新计算do
或while
语句的控制表达式。在
for
循环中(使用语法for( <init-expr> ; <cond-expr> ; <loop-expr> )
),将执行<loop-expr>
子句。 然后,重新计算<cond-expr>
子句,并根据结果确定该循环结束还是进行另一个迭代。
下面的示例演示了如何使用 continue
语句跳过代码部分并启动循环的下一个迭代。
示例
// continue_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
i++;
printf_s("before the continue\n");
continue;
printf("after the continue, should never print\n");
} while (i < 3);
printf_s("after the do loop\n");
}
before the continue
before the continue
before the continue
after the do loop
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈