- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
break, continue and label in Java loop
Following example showcases labels 'first', 'second' before a for statement and use the break/continue controls to jump to that label. See the example below.
Example
public class Tester { public static void main(String args[]) { first: for (int i = 0; i < 3; i++) { for (int j = 0; j< 3; j++){ if(i == 1){ continue first; } System.out.print(" [i = " + i + ", j = " + j + "] "); } } System.out.println(); second: for (int i = 0; i < 3; i++) { for (int j = 0; j< 3; j++){ if(i == 1){ break second; } System.out.print(" [i = " + i + ", j = " + j + "] "); } } } }
first is the label for first outermost for loop and continue first cause the loop to skip print statement if i = 1;
second is the label for second outermost for loop and continue second cause the loop to break the loop.
- Related Articles
- Describe JavaScript Break, Continue and Label Statements
- How to control for loop using break and continue statements in C#?
- Difference between continue and break statements in Java
- How to use break and continue statements in Java?
- Java continue statement with Loop
- Difference Between break and continue
- Loops and Control Statements (continue, break and pass) in Python
- Finding how many time a specific letter is appearing in the sentence using for loop, break, and continue - JavaScript
- 'break' and 'continue' in forEach in Kotlin
- What is the difference between break and continue statements in C#?
- What is the difference between break and continue statements in JavaScript?
- How to use continue statement in Python loop?
- What is the difference between break with a label and without a label in JavaScript?
- How to break a loop in JavaScript?
- How can I use a label with continue statement in JavaScript?

Advertisements