Computer Applications
What action will you take to terminate an outer loop from the block of an inner loop?
Java Nested for Loops
31 Likes
Answer
An outer loop can be terminated from the block of an inner loop by using Labelled break statement as shown in the below example:
outer: for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 10; j++) {
System.out.println(j);
if (i == 3)
break outer;
}
}
System.out.println("Outside outer loop");
Answered By
15 Likes