Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      continue statement

      From cppreference.com
      <c‎ |language
       
       
       
      Statements
      Labels
      Expression statements
      Compound statements
      Selection statements
      Iteration statements
      Jump statements
      continue
       

      Causes the remaining portion of the enclosingfor,while or do-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-spec-seq(optional)continue;
      attr-spec-seq -(C23)optional list ofattributes, applied to thecontinue statement

      [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,while, anddo-while loops).

      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 loop, it acts as:

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

      [edit]Keywords

      continue

      [edit]Example

      Run this code
      #include <stdio.h> int main(void){for(int i=0; i<10; i++){if(i!=5)continue;printf("%d ", i);// this statement is skipped each time i != 5} printf("\n"); for(int j=0; j<2; j++){for(int k=0; k<5; k++){// only this loop is affected by continueif(k==3)continue;printf("%d%d ", j, k);// this statement is skipped each time k == 3}}}

      Output:

      500 01 02 04 10 11 12 14

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 6.8.6.2 The continue statement (p: 111)
      • C11 standard (ISO/IEC 9899:2011):
      • 6.8.6.2 The continue statement (p: 153)
      • C99 standard (ISO/IEC 9899:1999):
      • 6.8.6.2 The continue statement (p: 138)
      • C89/C90 standard (ISO/IEC 9899:1990):
      • 3.6.6.2 The continue statement

      [edit]See also

      C++ documentation forcontinue statement
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/language/continue&oldid=130663"

      [8]ページ先頭

      ©2009-2025 Movatter.jp