How do I break out of nested loops in Java?
@lebyy▲ 0 net votes
Problem: I've got a nested loop construct like this: for (Type type : types) { for (Type t : types2) { if (some condition) { // Do something and break... break; // Breaks ou Now how can I break out of both loops? I've looked at similar questions, but none concerns… Fix (from the top answer): Like other answerers, I'd definitely prefer to put the loops in a different method, at which point you can just return to stop iterating completely. This answer just shows how the requirements in the question can be met. You can use break with a label for the outer loop. For example: public class Test { public static…