continue
     
     statement
    
    | General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
| 
 | ||||||||||||||||
| Jump statements | ||||||||||||||||
| 
 | ||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
| 
                 inline
                specifier | ||||||||||||||||
| Dynamic exception specifications ( until C++17* ) | ||||||||||||||||
| 
                 noexcept
                specifier
               
               
                (C++11) | ||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
| 
 | ||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean - Integer - Floating-point | ||||||||||||||||
| Character - String - nullptr (C++11) | ||||||||||||||||
| User-defined (C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes (C++11) | ||||||||||||||||
| Types | ||||||||||||||||
| 
                 typedef
                declaration | ||||||||||||||||
| Type alias declaration (C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
| 
 | ||||||||||||||||
| Special member functions | ||||||||||||||||
| 
 | ||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
导致外围的 for 、 range-for 、 while 或 do-while 循环体中剩余部分被跳过。
当使用条件语句忽略循环剩余部分显得笨拙时使用。
| 目录 | 
语法
| attr
         
         
         
          (可选) 
          
           continue
          
         
          
           ;
          
          | |||||||||
说明
       
        continue
       
       语句会导致一次跳转,如同通过
       
        goto
       
       跳转到循环体末尾(该语句仅可出现在
       
        for
       
       、
       
        range-for
       
       、
       
        while
       
       及
       
        do-while
       
       循环的循环体内)。
      
更准确地说,
对于 while 循环,其作用为
while (/* ... */) { // ... continue; // 作用等同于 goto contin; // ... contin:; }
对于 do-while 循环,其作用如下:
do { // ... continue; // 作用等同于 goto contin; // ... contin:; } while (/* ... */);
对于 for 循环和 range-for 循环,其作用方式为:
for (/* ... */) { // ... continue; // 作用等同于 goto contin; // ... contin:; }
关键词
示例
#include <iostream> int main() { for (int i = 0; i < 10; ++i) { if (i != 5) continue; std::cout << i << ' '; // 该语句在每次 i != 5 时被跳过 } std::cout << '\n'; for (int j = 0; 2 != j; ++j) for (int k = 0; k < 5; ++k) // 只有该循环受 continue 影响 { if (k == 3) continue; // 该语句在每次 k == 3 时被跳过: std::cout << '(' << j << ',' << k << ") "; } std::cout << '\n'; }
输出:
5 (0,0) (0,1) (0,2) (0,4) (1,0) (1,1) (1,2) (1,4)
参见
| 
          
           
            C 文档
           
          
          关于
          
           
            continue
           
          
          |