Exit from nested for loops in java

There are 2 nested for loops in your code and if we want to exit both the loops at a time once a particular condition satisfies.
If we write break once the condition satisfies, control exits from inner for loop, but main for loop runs as usual, we want to basically exit this main loop as well.

Lets see the code implementation:


We will be searching a number in an array (2 dim), if found in that array, then stop searching and come out of both the loops.

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: