Home > Java > JavaBase > How to get out of for loop in java

How to get out of for loop in java

王林
Release: 2019-11-18 11:14:58
Original
4060 people have browsed it

How to get out of for loop in java

1. Problem description

How to jump out of the outermost loop when there are multiple for loops?

2. Solution

2.1 Normal single for loop

How to get out of for loop in java

To jump out of a single-layer loop, use break to jump out normally.

How to get out of for loop in java

#2.2 In the case of multi-layer loops, using break only jumps out of the innermost loop.

How to get out of for loop in java

It can be seen from the results that when i is greater than 3, the innermost i loop is jumped out, but the outer j loop is still executed normally.

2.3 Jump out of the specified layer loop

How to get out of for loop in java

# Simply put, give the for loop a name. The naming rule is: name half-width colon.

For example: jj:, and then follow the name after break to jump out of the corresponding for loop.

Recommended tutorial: Java tutorial

The above is the detailed content of How to get out of for loop in java. 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