Home > Java > JavaBase > body text

What is the function of continue statement

王林
Release: 2020-07-11 09:13:17
Original
21717 people have browsed it

The function of the continue statement is to end the current loop and enter the next loop. That is, only this loop ends, not all loops end, and subsequent loops still proceed. The continue statement can only be used in loop statements.

What is the function of continue statement

In Java language, the continue statement is used to end the current loop and enter the next loop. That is, only this loop ends, not all loops end. , the subsequent loop still proceeds.

(Recommended tutorial: java entry program)

Let’s take a look at an example:

public class Continue {
    public static void main(String[] args) {
        int count = 0;
        for(int i = 1; i <= 10; i++) {
            if(i == 5) {
                // 遍历到5的时候,就会跳过当前循环体,当然也不会去执行剩下的语句了。
                // 于是就到了下一轮循环(此时i的值是6),所以这里的第5次输出是6而非5,因为5的那一轮循环被跳过了。
                continue;
            }
            count++;
            System.out.println("第" + count + "次输出,输出值为" + i);
        }
    }
}
Copy after login

(Recommended video tutorial: java video Tutorial)

Output result:

What is the function of continue statement

The above is the detailed content of What is the function of continue statement. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!