Merge pull request #1581 from AkshayKalose/patch-3

Add For Loop Label Breaking in Java
This commit is contained in:
Adam Bard 2015-10-17 09:10:08 +08:00
commit d7124d029c

View File

@ -285,7 +285,18 @@ public class LearnJava {
// Iterated 10 times, fooFor 0->9
}
System.out.println("fooFor Value: " + fooFor);
// Nested For Loop Exit with Label
outer:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (i == 5 && j ==5) {
break outer;
// breaks out of outer loop instead of only the inner one
}
}
}
// For Each Loop
// The for loop is also able to iterate over arrays as well as objects
// that implement the Iterable interface.