非常教程

C参考手册

C 语法

continue statement

导致封闭的剩余部分 for,while 或 do-while 循环体被跳过。

当使用条件语句忽略循环的剩余部分时,使用它时很尴尬。

句法

continue ;

说明

continue语句会像跳转一样跳转到循环体的末尾(它可能只出现在for,while 和 do-while 循环的循环体内)。

对于 while 循环,它充当。

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

对于 do-while 循环,它的作用如下:

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

对于 for 循环,它的作用是:

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

关键词

continue.

#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 continue
            if (k == 3) continue;
            printf("%d%d ", j, k);    //this statement is skipped each time k==3
        }
    }
}

输出:

5
00 01 02 04 10 11 12 14

参考

  • 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

C 语法相关

1.#define directive
2.#elif directive
3.#else directive
4.#endif directive
5.#error directive
6.#if directive
7.#ifdef directive
8.#ifndef directive
9.#include directive
10.#line directive
11.#pragma directive
12.alignas
13.Alternative operators and tokens
14.Analyzability
15.Arithmetic operators
16.Arithmetic types
17.Array declaration
18.Array initialization
19.ASCII Chart
20.Assignment operators
21. types
22.Basic concepts
23.Bit fields
24.break statement
25.C language
26.C Operator Precedence
27.cast operator
28.character constant
29.Comments
30.Comparison operators
31.compound literals
32.Conditional inclusion
33.Conformance
34.const type qualifier
35.Constant expressions
36.Declarations
37.do-while loop
38.Enumerations
39.Escape sequences
40.Expressions
41.External and tentative definitions
42.File scope
43.floating constant
44.for loop
45.Function declarations
46.Function definitions
47.Functions
48.Generic selection
49.goto statement
50.Identifier
51.if statement
52.Implicit conversions
53.Increment/decrement operators
54.Initialization
55.inline function specifier
56.integer constant
57.Lifetime
58.Logical operators
59.Lookup and name spaces
60.Main function
61.Member access operators
62.Memory model
63.Objects and alignment
64.Order of evaluation
65.Other operators
66.Phases of translation
67.Pointer declaration
68.Preprocessor
69.restrict type qualifier
70.return statement
71.Scalar initialization
72.Scope
73.sizeof operator
74.Statements
75.static assert declaration
76.Static storage duration
77.Storage-class specifiers
78.string literals
79.Struct and union initialization
80.Struct declaration
81.switch statement
82.Thread storage duration
83.Type
84.Type
85.Typedef declaration
86.Undefined behavior
87.Union declaration
88.Value categories
89.Variadic arguments
90.volatile type qualifier
91.while loop
92._Alignof operator
93._Noreturn function specifier
C

C 语言是一门通用计算机编程语言,应用广泛。C 语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。