Created
December 7, 2011 02:01
-
-
Save andy-morris/1441082 to your computer and use it in GitHub Desktop.
TIL java can break from arbitrary named blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
static void println(String s) { System.out.println(s); } | |
public static void main(String args[]) { | |
println("A"); | |
foo: { | |
println("B"); | |
if (true) break foo; | |
println("C"); | |
} | |
println("D"); | |
} | |
} | |
/* | |
* anders:~ i» javac Foo.java && java Foo | |
* A | |
* B | |
* D | |
* | |
* (ps. the "if (true)" is to shut up an unreachable code error.) | |
* (pps. unsurprisingly `continue` doesn't work for nonloops.) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment