Transfer Statements – Control Flow
4.9 Transfer Statements Java provides the following language constructs for transferring control in a program: The throw statement can also transfer control in a program (§7.4, p. 386). 4.10 Labeled Statements A statement may have a label: label :statement A label is any valid identifier; it always immediately precedes the statement. Label names exist in their own namespace, so that they do not conflict with names of packages, classes, interfaces, methods, fields, and local variables. The scope of a label is the statement prefixed by the label, meaning that it cannot be redeclared as a label inside the labeled statement—analogous to the scope of local variables. Click here to view code image L1: if (i > 0) { L1: System.out.println(i); // (1) Not OK. Label L1 redeclared.}L1: while (i < 0) { // (2) OK. L2: System.out.println(i);}L1: { // (3) OK. Labeled block. int j = 10; System.out.println(j);}L1: try { //…