Skip to content

Instantly share code, notes, and snippets.

@andy-morris
Created December 7, 2011 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy-morris/1441082 to your computer and use it in GitHub Desktop.
Save andy-morris/1441082 to your computer and use it in GitHub Desktop.
TIL java can break from arbitrary named blocks
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