Home > Backend Development > C#.Net Tutorial > The continue statement is only used in loop statements. What is its function?

The continue statement is only used in loop statements. What is its function?

青灯夜游
Release: 2022-12-30 11:13:20
Original
18526 people have browsed it

The continue statement is only used in loop statements. Its function is to skip the remaining statements in the loop body and force entry into the next loop. The continue statement is only used in while and for loops, and is often used together with if conditional statements to determine whether the conditions are true.

The continue statement is only used in loop statements. What is its function?

The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.

The continue statement is only used in while and for loops. Its function is to skip the remaining statements in the loop body and force entry into the next loop.

For the while loop, continue to solve the loop condition. For the for loop program flow, the third part of the expression in the for statement header is then solved.

The continue statement is only used in loop statements. What is its function?

Flowchart:

The continue statement is only used in loop statements. What is its function?

Example:

#include <stdio.h>
int main(){
    char c = 0;
    while(c!=&#39;\n&#39;){  //回车键结束循环
        c=getchar();
        if(c==&#39;4&#39; || c==&#39;5&#39;){  //按下的是数字键4或5
            continue;  //跳过当次循环,进入下次循环
        }
        putchar(c);
    }
    return 0;
}
Copy after login

Run result:

0123456789↙
01236789
Copy after login

When the program encounters while, the value of variable c is '\0', the loop condition c!='\n' is established, and the first loop starts. getchar() causes the program to pause execution, wait for user input, and does not start reading characters until the user presses the Enter key.

In this example, we input 0123456789. When 4 or 5 is read, the if condition c=='4'||c=='5' is established, and the continue statement is executed to end the current loop. , directly enter the next loop, which means putchar(c); will not be executed. When other numbers are read, the if condition does not hold, the continue statement will not be executed, and putchar(c); will output the read characters.

For more knowledge about computer programming, please visit: Introduction to Programming! !

The above is the detailed content of The continue statement is only used in loop statements. What is its function?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template