Friday 1 April 2016

java - Breaking out off a WHILE loop which is inside a FOR LOOP





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{
.
.
.

While{
.
.
;
}
}
}

Answer



use a label and a break




here:

while (...) {
for (...) {

if (...) break here;
}
}



see https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...