This code just made me stare at my screen for a few minutes:
loop:
for (;;) {
// ...
}
I have never seen this before, and I had no idea Java has a "loop" keyword (Netbeans doesn't even color it like a keyword), and it does compile fine with JDK 6.
Can someone explain this to me?
It is not a keyword, but a label. If inside the for loop you write
break loop;
, you exits that loopYou could write almost anything, as it is a label... You have an example here
It's a label, though look at the following example:
When
b>10
the execution flow goes to the outer loopIt is a label, and labels in java can be used with the
break
andcontinue
key words for additional control over loops. Here it is explained in a rather good way: http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ305_024.htmit is a label. generaly label used in java to transfer the control flow at desired location while all keyword like continue, break have a specified chice of location.
Its a break point label, to allow you to break out of a specified loop, rather than simply the innermost one you happen to be in.
Its used on line 148