continue 语句 (C)continue Statement (C)

continue 语句将控制传递给它在其中出现的最近的封闭 doforwhile 语句的下一个迭代,并绕过 doforwhile 语句主体中的任何剩余语句。The continue statement passes control to the next iteration of the nearest enclosing do, for, or while statement in which it appears, bypassing any remaining statements in the do, for, or while statement body.



确定 doforwhile 语句的下一次迭代,如下所示:The next iteration of a do, for, or while statement is determined as follows:

  • dowhile 语句中,下一个迭代首先会重新计算 dowhile 语句的表达式。Within a do or a while statement, the next iteration starts by reevaluating the expression of the do or while statement.

  • continue 语句中的 for 语句会导致计算 for 语句的循环表达式。A continue statement in a for statement causes the loop expression of the for statement to be evaluated. 然后,编译器会重新计算条件表达式并根据结果终止或迭代语句主体。Then the compiler reevaluates the conditional expression and, depending on the result, either terminates or iterates the statement body. 有关 for 语句及其非终止符的详细信息,请参阅 for 语句See The for Statement for more information on the for statement and its nonterminals.

    以下是 continue 语句的示例:This is an example of the continue statement:

while ( i-- > 0 )   
    x = f( i );  
    if ( x == 1 )  
    y += x * x;  

在此示例中,当 i 大于 0 时,将执行语句主体。In this example, the statement body is executed while i is greater than 0. 首先将 f(i) 赋给 x;然后,如果 x 等于 1,则执行 continue 语句。First f(i) is assigned to x; then, if x is equal to 1, the continue statement is executed. 主体中的语句的其余部分将被忽略,并且执行将通过计算循环的测试来基于循环恢复。The rest of the statements in the body are ignored, and execution resumes at the top of the loop with the evaluation of the loop's test.

另请参阅See Also

continue 语句continue Statement