Chris Smith sez:
....
As for whether labeled break and continue are still a good idea, I doubt
it. I have really found myself using them only in one situation:
namely, when I'm playing around at
www.topcoder.com, and the important
thing is whether it takes four minutes or six minutes to write some
piece of code. Then labeled break and continue are quite useful.
About the only time you need a goto in a structured high-level
language is when structured constructs don't do what you need.
Most common by far is a loop with condition in the middle --
structured programming offers only loop with a counter and
pre- and post-condition loops. Hence break and continue.
Labelled versions allow breaking out of several levels of
nested loops. That does come up occasionally, but not nearly
as often as breaking out of innermost loop. I almost never
use it, either, but off the top of my head:
out: for( row=0; row<a.length; row++ )
for( col=0; col<a[row].length; col++ )
if( a[row][col] == search_value )
break out;
As for the other usage of Java labelled break (quite
different from breaking out of a nested loop):
end: {
...
break end;
}
somestatement;
and
...
goto end;
end: somestatement;
both jump to somestatement. The former version limits the
mess you can create (makes it harder to jump back and forth
all over the place), that's all. Still a goto, only castrated
and chained to a pair of curly braces.
Dima