Home>Article>Java> What are the functions of break and continue keywords in java

What are the functions of break and continue keywords in java

Mary-Kate Olsen
Mary-Kate Olsen Original
2020-05-31 15:56:33 3522browse

What are the functions of break and continue keywords in java

Let’s first look at the break keyword. The break keyword is mainly used in loop statements or switch statements to jump out of the entire statement block.

It can also jump out of the innermost loop and continue to execute the statements below the loop.

Grammar format

break;

For example:

What are the functions of break and continue keywords in java

##(Video tutorial recommendation:

java video)

Output result:

10 20

Then let’s take a look at the continue keyword. The continue keyword is suitable for any loop control structure. Its function is to make the program jump to the next time immediately. Iteration of the loop.

In a for loop, the continue statement allows the program to immediately jump to the update statement; in a while or do...while loop, the program immediately jumps to the judgment statement of the Boolean expression.

Grammar format:

continue;

Example:

What are the functions of break and continue keywords in java

Output result:

10 20 40 50

Recommended tutorial:

java Getting started

The above is the detailed content of What are the functions of break and continue keywords in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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