サーチ…


ブレーク

最も近いループまたはswitch文から抜け出します。

// print the numbers to a file, one per line
for (const int num : num_list) {
    errno = 0;
    fprintf(file, "%d\n", num);
    if (errno == ENOSPC) {
        fprintf(stderr, "no space left on device; output will be truncated\n");
        break;
    }
}

持続する

最小の囲みループの終わりにジャンプします。

int sum = 0;
for (int i = 0; i < N; i++) {
    int x;
    std::cin >> x;
    if (x < 0) continue;
    sum += x;
    // equivalent to: if (x >= 0) sum += x;
}

行う

do-whileループを紹介します

// Gets the next non-whitespace character from standard input
char read_char() {
    char c;
    do {
        c = getchar();
    } while (isspace(c));
    return c;
}

にとって

forループ、またはC ++ 11以降では、 範囲ベースのforループが導入されています

// print 10 asterisks
for (int i = 0; i < 10; i++) {
    putchar('*');
}

while

whileループを紹介します

int i = 0;
// print 10 asterisks
while (i < 10) {
    putchar('*');
    i++;
}

範囲ベースのforループ

std::vector<int> primes = {2, 3, 5, 7, 11, 13};

for(auto prime : primes) {
    std::cout << prime << std::endl;
}


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow