6.11. The continue Statement6.11. continue 语句A continue statement causes the current iteration of the nearest enclosing loop to terminate. Execution resumes with the evaluation of the condition in the case of a while or do while statement. In a for loop, execution continues by evaluating the expression inside the for header. continue 语句导致最近的循环语句的当次迭代提前结束。对于 while 和 do while 语句,继续求解循环条件。而对于 for 循环,程序流程接着求解 for 语句头中的 expression 表达式。 For example, the following loop reads the standard input one word at a time. Only words that begin with an underscore will be processed. For any other value, we terminate the current iteration and get the next input: 例如,下面的循环每次从标准输入中读入一个单词,只有以下划线开头的单词才做处理。如果是其他的值,终止当前循环,接着读取下一个单词: string inBuf; while (cin >> inBuf && !inBuf.empty()) { if (inBuf[0] != '_') continue; // get another input // still here? process string ... } A continue can appear only inside a for, while, or do while loop, including inside blocks nested inside such loops. continue 语句只能出现在 for、while 或者 do while 循环中,包括嵌套在这些循环内部的块语句中。
![]() |