Java Deep

Pure Java, what else

No loop, do break

axReading 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…)

Advertisements

One response to “No loop, do break

  1. lukaseder April 7, 2013 at 8:17 am

    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

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: