- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
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