BLOCKS AND STATEMENTS
The
break
Statement
14.13
14.13 The
break
Statement
A break statement transfers control out of an enclosing statement.
BreakStatement:
break
Identifier
opt
;
A
break
statement with no label attempts to transfer control to the innermost
enclosing
switch
,
while
,
do
, or
for
statement; this statement, which is called the
break target
, then immediately completes normally. To be precise, a
break
state
ment with no label always completes abruptly, the reason being a
break
with no
label. If no
switch
,
while
,
do
, or
for
statement encloses the
break
statement, a
compile time error occurs.
A
break
statement with label
Identifier
attempts to transfer control to the
enclosing labeled statement ( 14.6) that has the same
Identifier
as its label; this
statement, 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.
To be precise, a
break
statement with label
Identifier
always completes abruptly,
the reason being a
break
with label
Identifier
. If no labeled statement with
Identifier
as its label encloses the
break
statement, a compile time error occurs.
It can be seen, then, that a
break
statement always completes abruptly.
The preceding descriptions say attempts to transfer control rather than just
transfers control because if there are any
try
statements ( 14.18) within the
break target whose
try
blocks contain the
break
statement, then any
finally
clauses of those
try
statements are executed, in order, innermost to outermost,
before control is transferred to the break target. Abrupt completion of a
finally
clause can disrupt the transfer of control initiated by a
break
statement.
In the following example, a mathematical graph is represented by an array of
arrays. A graph consists of a set of nodes and a set of edges; each edge is an arrow
that points from some node to some other node, or from a node to itself. In this
example it is assumed that there are no redundant edges; that is, for any two nodes
P
and
Q
, where
Q
may be the same as
P
, there is at most one edge from
P
to
Q
.
Nodes are represented by integers, and there is an edge from node
i
to node
edges[i ][j ]
for every
i
and
j
for which the array reference
edges[i ][j ]
does not throw an
IndexOutOfBoundsException
.
The task of the method
loseEdges
, given integers
i
and
j
, is to construct a
new graph by copying a given graph but omitting the edge from node
i
to node
j
,
if any, and the edge from node
j
to node
i
, if any:
283
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved