mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
Add For Loop Label Breaking in Java
This commit is contained in:
parent
9bb82465e6
commit
9f822a0a25
@ -286,6 +286,17 @@ public class LearnJava {
|
|||||||
}
|
}
|
||||||
System.out.println("fooFor Value: " + fooFor);
|
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
|
// For Each Loop
|
||||||
// The for loop is also able to iterate over arrays as well as objects
|
// The for loop is also able to iterate over arrays as well as objects
|
||||||
// that implement the Iterable interface.
|
// that implement the Iterable interface.
|
||||||
|
Loading…
Reference in New Issue
Block a user