> Break statement in java ~ Online tutorial

Break statement in java

The break Statement
A break statement transfers control out of an enclosing statement.
BreakStatement:
break Identifieropt ;
  • A break statement with no label attempts to transfer control to the innermost
    enclosing switch, while, do, or for statement of the immediately enclosing
    method or initializer block; this statement, which is called the break target, then
    immediately completes normally.
  • To be precise, a break statement with no label always completes abruptly, the
    reason being a break with no label.
  • If no switch, while, do, or for statement in
    the immediately enclosing method, constructor or initializer encloses the break
    statement, a compile-time error occurs.
  • A break statement with label Identifier attempts to transfer control to the
    enclosing labeled statement that has the same Identifier as its label; thisstatement, which is called the break target, then immediately completes normally.
  • In this case, the break target need not be a while, do, for, or switch statement.
  • A break statement must refer to a label within the immediately enclosing method
    or initializer block. There are no non-local jumps.
Prorgam


class Graph
{
int edges[][];
public Graph(int[][] edges)
{
 this.edges = edges;
}
public Graph loseEdges(int i, int j)
 {
int n = edges.length;
int[][] newedges = new int[n][];
for (int k = 0; k < n; ++k)
{
 edgelist:
 {
int z;
 search:
 {
if (k == i)
{
for (z = 0; z < edges[k].length; ++z)
 if (edges[k][z] == j)
break search;
 }
else if (k == j)
{
 for (z = 0; z < edges[k].length; ++z)
 if (edges[k][z] == i) break search;
}
 // No edge to be deleted;
share this list. newedges[k] = edges[k]; break edgelist;
 }
//search // Copy the list, omitting the edge at position z.
int m = edges[k].length - 1;
int ne[] = new int[m];
System.arraycopy(edges[k], 0, ne, 0, z);
 System.arraycopy(edges[k], z+1, ne, z, m-z);
 newedges[k] = ne; 

//edgelist
}
 return new Graph(newedges); 
}
 }


buy it now





Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: