Home > 类库下载 > java类库 > body text

Break and continue in java jump out of the specified loop

高洛峰
Release: 2016-10-20 11:36:22
Original
2410 people have browsed it

 break and continue in java can jump out of the specified loop

 break and continue in java can jump out of the specified loop. If no loop name is added after break and continue, it will jump out of the loop by default. If you add the specified loop name after it, you can jump out of the loop. Specify a loop (the specified loop is usually an outer loop nested within a loop).

  Break jumps out of the specified loop sample code:

loop1:for(int x = 0; x < 4; x++)
        {
            loop2:for (int y = 0; y < 5 ; y++ )
            {
                System.out.println("x="+x+",y="+y);
                if (y==2)
                {
                    break loop1;
                }
            }
        }
Copy after login

Code running results:

Break and continue in java jump out of the specified loop

Continue Jumps out of the specified loop sample code:

loop1:for(int x = 0; x < 4; x++)
        {
            loop2:for (int y = 0; y < 5 ; y++ )
            {    if (x==2)
                {
                    continue loop1;
                }
                System.out.println("x="+x+",y="+y);
            }
        }
Copy after login

Code running results:

Break and continue in java jump out of the specified loop

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