Reading the standard of the Java language I found something interesting. Something that implies that break can be used without a loop, and not only inside a loop but inside any block. And it does:

package wierdo;

public class Wierdo {
	public static void main(String[] args) {
		label: {
			if (args.length == 0)
				break label;
			System.out.println("We happy, we have arguments!");
		}
		System.out.println("Hello Wierldo!");
	}
}

Weird, is it? You can read some more on this.

Practical consequences? If you are an architect and you work with subordinates: keep an axe by your side to chop off hands writing those in prod code. If you are coders: mind the architect approaching with the axe. (Just kidding…​)

Comments imported from Wordpress

lukaseder 2013-04-07 08:17:14

Yeah. That twisted "goto" emulation has proven handy millions of times in my code ;-) You can also "jump backwards" using "continue" to leverage the byte-code "goto" instruction: http://stackoverflow.com/a/6373262/521799


Comments

Please leave your comments using Disqus, or just press one of the happy faces. If for any reason you do not want to leave a comment here, you can still create a Github ticket.