diff options
author | Akshay Kalose <AkshayProductions@gmail.com> | 2015-10-16 21:03:46 -0400 |
---|---|---|
committer | Akshay Kalose <AkshayProductions@gmail.com> | 2015-10-16 21:03:46 -0400 |
commit | 9f822a0a25776f1c3d384da31970fa33301f3b3c (patch) | |
tree | a6f2d721328e483a8ef136beeabe3ef8c7f84b98 | |
parent | 9bb82465e6ad4b602f4fb0a8ff3877dddc4ca3e5 (diff) |
Add For Loop Label Breaking in Java
-rw-r--r-- | java.html.markdown | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/java.html.markdown b/java.html.markdown index 35ec57d8..6aff5b6f 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -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. |