continue 语句导致最近的循环语句的当次迭代提前结束。对于 while 和 do while 语句,继续求解循环条件。而对于 for 循环,程序流程接着求解 for 语句头中的 expression 表达式。
例如,下面的循环每次从标准输入中读入一个单词,只有以下划线开头的单词才做处理。如果是其他的值,终止当前循环,接着读取下一个单词:
string inBuf;
while (cin >> inBuf && !inBuf.empty()) {
if (inBuf[0] != '_')
continue; // get another input
// still here? process string ...
}
continue 语句只能出现在 for、while 或者 do while 循环中,包括嵌套在这些循环内部的块语句中。