Originally posted by Ajith Kallambella:
The break statement may not serve as an alternative to the return statement since it ( former ) can be used only in loop-structures.
Ajith
but i think break can be used any where there is a possibility of creating a local scope. whether it may be a if-else or swith or try-catch etc construct.
here is supporting code.
<pre>
class
Test {
public static void main(
String arg[]) {
int i=8;
label1:
if (i>3)
{
System.out.println("label allowed");
break label1;
}
label2:
switch(i)
{
case 1: System.out.println("again allowed");
break label2;
}
label3:
try {
System.out.println("again allowed");
break label3;
}
catch(RuntimeException re) {}
}
}
</pre>