Linked Questions
80 questions linked to/from How do I break out of nested loops in Java?
33
votes
9
answers
42k
views
How do I break multiple foreach loops? [duplicate]
I have four foreach loops that iterate through the collections and based on a condition do something.
Here is the code that I am writing now:
boolean breakFlag = false;
String valueFromObj2 = null;
...
44
votes
6
answers
61k
views
How do exit two nested loops? [duplicate]
I have been using Java for quite some time, yet my education in loops is somewhat lacking. I know how to create every loop that exists in java and break out of the loops as well. However, I've ...
39
votes
6
answers
31k
views
How do I break from the main/outer loop in a double/nested loop? [duplicate]
If I have loop in a loop and once an if statement is satisfied I want to break main loop, how am I supposed to do that?
This is my code:
for (int d = 0; d < amountOfNeighbors; d++) {
for (int ...
2
votes
6
answers
4k
views
Breaking out of nested for loops in Java [duplicate]
Possible Duplicate:
Breaking out of nested loops in Java
How can I use break and/or continue statements to return to the first line of the while loop at points 1, 2 and 3, for example, as ...
1
vote
1
answer
7k
views
Double break java [duplicate]
I am programming with Java, and I do not understand how to use the break; command to get out of more than one loop.
Here is some code that I tried:
while (true){
System.out.println("\n\...
8
votes
4
answers
652
views
Breaking nested loop and main loop [duplicate]
I have the following code:
int x = 100; //Or some other value
while(x > 0) {
for(int i = 5; i > 0; i++) {
x = x-2;
if(x == 0)
break;
}
}
However, ...
0
votes
2
answers
3k
views
loop break not working inside switch block on array of strings [duplicate]
Please refer the below code in which loop break does not work inside the switch block, can you help?
String Books[] = { "Harry Potter", "To Kill a Mocking Bird", "Hunger Games" };
//For loop ...
3
votes
3
answers
1k
views
Conditionally breaking for loops in Java [duplicate]
I am trying to see if the multidimensional array is rectangular or not. I am new to programming and can't exactly figure out why the "break;" will not kick me out of the loop and it continues to run. ...
1
vote
1
answer
3k
views
Break while loop inside for loop Java [duplicate]
Loop is work fine.
while (!(list.contains("NORTH SOUTH") || list.contains("SOUTH NORTH") || list.contains("WEST EAST") || list.contains("EAST WEST"))) {
for (int i = 0; i < list.size(); ...
4
votes
2
answers
793
views
Breaking out off a WHILE loop which is inside a FOR LOOP [duplicate]
In Java, what is the direct method of getting out of a WHILE loop which is inside a WHILE loop and which is inside a FOR loop?
The structure should look something like this:
For{
.
.
While{
.
...
0
votes
2
answers
634
views
Break 2 loops if condition satisfied in Java [duplicate]
public class Newfile{
public static void main(String []args){
for(int a=1; a < 5; a++){
for(int b=1; b < 5; b++){
if(a == b){
...
0
votes
2
answers
791
views
How to break if loop in java [duplicate]
I tried putting the break after clicking an element, but after clicking the element it tries to iterate again
for (int i = 1; i < tableSize; i++) {
final List<WebElement> ...
1
vote
6
answers
488
views
Breaking 2 nested loops "at once" [duplicate]
Please have a look at the following code (Java)
while((str=br.readLine())!=null)
{
int tempCounter=0;
for(int i=0;i<str.length();i=i+3)
{
...
-2
votes
2
answers
329
views
How to exit from foreach loop? Which using enum data [duplicate]
I wanted to implement a game with levels and after winning the current level, the user can solve another one. I did it by for each loop using enum data. If you have a another way of solving this ...
0
votes
1
answer
289
views
break inside for loop within while loop [duplicate]
I tried to break out of a for loop but it doesn't break.
How do I get or break out of this do...while loop from inside of the for loop?
Here CompanyEmployee is an ArrayList of objects of the ...