What is the purpose of the continue statement in the C programming language?

In C language, the continue statement is used to skip the remaining code in the current loop and proceed directly to the next iteration. It is mainly used for two purposes:

  1. keep going

Example code:

for (int i = 0; i < 10; i++) {
    if (i == 5) {
        continue;
    }
    printf("%d ", i);
}

Output result:

0 1 2 3 4 6 7 8 9
  1. keep going

Code example:

for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
        if (j == 3) {
            continue;
        }
        printf("%d-%d ", i, j);
    }
}

The output is as follows:

0-0 0-1 0-2 1-0 1-1 1-2 2-0 2-1 2-2 3-0 3-1 3-2 4-0 4-1 4-2

It is important to note that the continue statement can only be used in loop statements and cannot be used in other statements such as switch statements or if statements.

bannerAds