Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Breaking out of nested loop in java
Yes, break statement can be used in nested for loops. It works on the for loop in which it is applied. See the example below.
Example
public class Tester {
public static void main(String[] args) {
for(int i = 0; i< 2; i++) {
for(int j = 0; j < 2; j++){
if(i == 1) {
break;
}
System.out.println("i = " + i+",j = " + j);
}
}
}
} Advertisements
