Home > Backend Development > C++ > How to use continue in C language

How to use continue in C language

下次还敢
Release: 2024-05-02 20:09:14
Original
945 people have browsed it

The function of the continue statement in C language is to skip the remaining part of the loop and directly continue executing the next round of loop. Usage: 1. Can only be used in loop structures; 2. The statement is placed at the position that needs to be skipped; 3. The effect is to skip the remaining statements and go to the next iteration.

How to use continue in C language

Usage of continue in C language

The continue statement is a control flow statement in C language. Used to skip the remainder of the loop and continue directly to the next iteration of the loop.

Usage:

continue statement can only be used in loop structures (for, while, do-while). It is placed where the remainder of the loop needs to be skipped.

Effect:

When a continue statement is encountered, the remaining statements in the loop will be skipped, and the program will go directly to the next iteration of the loop.

Example:

<code class="c">for (int i = 0; i < 10; i++) {
    if (i % 2 == 0) {
        continue;
    }
    printf("%d\n", i);
}</code>
Copy after login

In this example, the continue statement is used to skip even numbers. Therefore, the output will be:

<code>1
3
5
7
9</code>
Copy after login

Note: The

  • continue statement can only skip the remainder of the loop, it cannot break out of the loop.
  • If the continue statement is in the last statement of the loop, it has no effect.
  • The continue statement can be used in conjunction with the break statement to implement more complex loop control logic.

The above is the detailed content of How to use continue in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template