Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      continue statement

      From cppreference.com
      <cpp‎ |language
       
       
      C++ language
      General topics
      Flow control
      Conditional execution statements
      Iteration statements (loops)
      Jump statements
      continue -break
      Functions
      Function declaration
      Lambda function expression
      inline specifier
      Dynamic exception specifications(until C++17*)
      noexcept specifier(C++11)
      Exceptions
      Namespaces
      Types
      Specifiers
      constexpr(C++11)
      consteval(C++20)
      constinit(C++20)
      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
       
       

      Causes the remaining portion of the enclosingfor,range-for,while ordo-while loop body to be skipped.

      Used when it is otherwise awkward to ignore the remaining portion of the loop using conditional statements.

      Contents

      [edit]Syntax

      attr (optional)continue;

      [edit]Explanation

      Thecontinue statement causes a jump, as if bygoto to the end of the loop body (it may only appear within the loop body offor,range-for,while, anddo-while loops).

      More precisely,

      Forwhile loop, it acts as

      while(/* ... */){// ...continue;// acts as goto contin;// ...   contin:;}

      Fordo-while loop, it acts as:

      do{// ...continue;// acts as goto contin;// ...    contin:;}while(/* ... */);

      Forfor andrange-for loop, it acts as:

      for(/* ... */){// ...continue;// acts as goto contin;// ...    contin:;}

      [edit]Keywords

      continue

      [edit]Example

      Run this code
      #include <iostream> int main(){for(int i=0; i<10;++i){if(i!=5)continue;std::cout<< i<<' ';// this statement is skipped each time i != 5}std::cout<<'\n'; for(int j=0;2!= j;++j)for(int k=0; k<5;++k)// only this loop is affected by continue{if(k==3)continue;// this statement is skipped each time k == 3:std::cout<<'('<< j<<','<< k<<") ";}std::cout<<'\n';}

      Output:

      5(0,0) (0,1) (0,2) (0,4) (1,0) (1,1) (1,2) (1,4)

      [edit]See also

      C documentation forcontinue
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/language/continue&oldid=172494"

      [8]ページ先頭

      ©2009-2025 Movatter.jp